Ionic 3: ng-change doesn't work

↘锁芯ラ 提交于 2019-12-04 01:57:53

问题


I have a input field where a user can input his address and get auto-suggestions:

 <ion-label color="primary" stacked>Adresse:</ion-label>
        <ion-input type="text" ng-model="autocomplete.query" ng-change="updateSearch()"></ion-input>

My class has a update method where i want to do something, but unfortunately he doesn't get into it.

updateSearch()
  {
    console.log('aaa');
    if (this.autocomplete.query == '') {
      this.autocompleteItems = [];
      return;
    }
}

Any ideas?


回答1:


ng-model and ng-change were used in Angular 1.

With Ionic >= 2, you can use ngModel and ionChange.

<ion-input
  type="text"
  [(ngModel)]="autocomplete.query"
  (ionChange)="updateSearch()">
</ion-input>

The parentheses signify that data binding is from the template to the component, the square brackets, component to the template. When both are present, it is a two way data binding.

For more info on template syntax, look at the Angular docs.



来源:https://stackoverflow.com/questions/46491552/ionic-3-ng-change-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!