<input type="text" name="username" [(ngModel)]="{{_current + 1}}">
作为代码,我想给ngModel绑定(bind)一个表达式,但是报错,为什么? 我该怎么做?
最佳答案
您可以使用ngModelChange
:
@Component(
selector: 'my-component',
templateUrl: './my-component.component.html',
)
export class MyComponent{
_current: number;
onChange(){
this._current= this._current+ 1;
}
}
my-component.component.html
<input type="text" name="username" [(ngModel)]="_current" (ngModelChange)="onChange()">
关于Angular 2 ngModel 无法绑定(bind)表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49548138/