0

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?

Jim Peeters
  • 2,573
  • 9
  • 31
  • 53

2 Answers2

1

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).

Thalaivar
  • 23,282
  • 5
  • 60
  • 71
1

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');
  }
};
thepio
  • 6,193
  • 5
  • 35
  • 54