有沒有在angular2綁定中使用數學函數的方法?angular2綁定中的數學函數
例如
<div class="partition-panel">
<b class="pull-left">{{Math.round(variable/12*2)}}</b>
<b class="pull-right">{{Math.round(variable/12*2)}}</b>
</div>
時嘗試使用此我得到錯誤
Cannot read property 'round' of undefined
而且類似的問題的答案爲angular1
問題是,從模板中你只能訪問你的'Component'的局部範圍,所以你必須定義一個輔助方法或將'window.Math'賦值給Adrien建議的成員變量。 – rinukkusu