簡體   English   中英

angular2 + ngModel不能綁定表達式嗎?

[英]angular2+ ngModel can not binding an expression?

<input type="text" name="username" [(ngModel)]="{{_current + 1}}">

作為代碼,我想將表達式綁定到ngModel,但是報告錯誤,為什么? 我該怎么辦?

您可以使用ngModelChange

@Component(
 selector: 'my-component',
 templateUrl: './my-component.component.html',
)
export class MyComponent{
 _current: number;

 onChange(){
   this._current= this._current+ 1;
 }
}

我-component.component.html

<input type="text" name="username" [(ngModel)]="_current" (ngModelChange)="onChange()">

您無法使用插值方法與模型綁定,您應該這樣做(沒有{{}} ):

<input type="text" name="username" [(ngModel)]="_current">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM