Angular 更改绑定的数据?

Angular 更改绑定的数据?,angular,angular2-template,angular2-components,Angular,Angular2 Template,Angular2 Components,在Angular 2中,是否有方法更改通过ngModel绑定到元素的数据? 例如: <input [(ngModel)]="color" /> 如何停止绑定颜色,并绑定color2(例如)和输入? 谢谢大家! 您可以使用函数来实现此行为。比如: my.component.ts ... getModelValue(){ if(contidionA){ return colorA; } else { return colorB;

在Angular 2中,是否有方法更改通过ngModel绑定到元素的数据? 例如:

<input [(ngModel)]="color" />

如何停止绑定颜色,并绑定color2(例如)和输入?
谢谢大家!

您可以使用函数来实现此行为。比如:

my.component.ts

...
getModelValue(){
    if(contidionA){
        return colorA;
    } else {
        return colorB;
    }
}
...
my.component.html

<input [(ngModel)]="getModelValue()" />

您可以使用函数来实现此行为。比如:

my.component.ts

...
getModelValue(){
    if(contidionA){
        return colorA;
    } else {
        return colorB;
    }
}
...
my.component.html

<input [(ngModel)]="getModelValue()" />