0
有没有办法在Angular 2中改变ngModel绑定到元素的数据? 例如:更改数据绑定?
<input [(ngModel)]="color" />
如何停止结合颜色和绑定COLOR2(例如)与输入? 谢谢!
有没有办法在Angular 2中改变ngModel绑定到元素的数据? 例如:更改数据绑定?
<input [(ngModel)]="color" />
如何停止结合颜色和绑定COLOR2(例如)与输入? 谢谢!
您可以使用函数来实现此行为。喜欢的东西:
my.component.ts
...
getModelValue(){
if(contidionA){
return colorA;
} else {
return colorB;
}
}
...
my.component.html
<input [(ngModel)]="getModelValue()" />