问题
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