如果我理解正确的话,单向数据绑定是从模型到视图,是使用双花括号 {{}} 或方括号 [] 实现的。
我想更新按钮内的计数器(徽章)。模型更改后不会自动反映更新,单击按钮后会更新。一切都在同一个组件中完成。
我的代码:
.html:
<button
mat-raised-button
matStepperNext
[matBadge]="polygonCounter"
matBadgePosition="below"
matBadgeColor="accent">
Next
</button>
.ts:
polygonCounter: number; //declared
ngOnInit() {
...
this.polygonCounter = 0;
...
}
改变值的函数:
onMapDrawed(e): void {
....
this.polygonCounter = 0;
let counter = 0;
...//function that get the new counter
this.polygonCounter = counter; //counter has the new value
}
这也不会在视图中更新,例如:
<p>{{polygonCounter}}</p>
我错过了什么吗?谢谢你。