Reputation: 2853
I am now calling controller methods when this inputfield is changing :
<input type="text" ng-model="query" ng-model-options='{ debounce: 500 }' ng-change="searchOnTags(query)"/>
How can I call a different method when the input field is empty again?
Upvotes: 0
Views: 955
Reputation: 6263
You can just use if statement inside your searchOnTags
function like this:
$scope.searchOnTags = function(query) {
console.log(query);
if (!query) {
console.log('input is empty');
}
};
Upvotes: 1
Reputation: 23632
Inside your searchOnTags
function check whether the form is $pristine
, which means the input
field is back to its initial state
.
When you edit a field it become dirty(ng-dirty
), when you clear the input you can set the form to pristine state(ng-pristine
).
Upvotes: 1