Reputation: 395
<input type="text" name="username" [(ngModel)]="{{_current + 1}}">
as the code, I want to banding an expression to ngModel, but report error, why? and how can I do it?
Upvotes: 2
Views: 156
Reputation: 1953
You can use 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()">
Upvotes: 3
Reputation: 5462
You can not bind with model using interpolation, you should do it like(without {{}}
):
<input type="text" name="username" [(ngModel)]="_current">
Upvotes: 2