0
我有一個angular2應用程序打字稿。我正試圖獲得當前時間。這裏是我的代碼模板解析錯誤:解析器錯誤:意外的令牌「日期」
<div>
<div class="row">
<div class="col-lg-6">
<div class="gotoAndBot-Copy-3" >
gotoAndBot
<span class="-copy-2">
{{new Date().toLocaleDateString()}}
</span>
</div>
</div>
</div>
</div>
,但它與Template parse errors: Parser Error: Unexpected token 'Date'
我wundering爲什麼它不承認Date
所以我怎樣才能修復它抱怨?
角2的模板語法不支持newing了對象(與任何對象嘗試)。 如果您需要日期,請在組件中將它初始化爲'currentTimeStamp = new Date()。toLocaleDateString()' ,然後在模板中引用currentTimeStamp。 – silentsod