gpt4 book ai didi

angular - angular2 绑定(bind)中的数学函数

转载 作者:太空狗 更新时间:2023-10-29 16:54:46 26 4
gpt4 key购买 nike

有没有办法在 angular2 绑定(bind)中使用数学函数?

示例

<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({
selector: 'my-app',
template: `
<div>
<h2>Hello {{math.round(number)}}</h2>
</div>
`,
})
export class App {
number = 2.5;
math = Math;
}

DEMO

关于angular - angular2 绑定(bind)中的数学函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40632467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com