Joe82 Joe82 - 2 years ago 118
AngularJS Question

AngularJS - Ng-route - Change ng-view when input:focus

I would like to change my view with ng-view. The point is that instead of firing an

event, I would need to do it when somebody starts typing in an
field (so I could achieve the same effect as when start typing in the search box in this page).

PS: I tried adding
to the input element, but that doesn't trigger the event. Any help would be much appreciated. Thanks!

Answer Source

All you need to do is to use ngChange directive with ngModelOptions (for debounce):

<input type="text" 
       ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 500, 'blur': 0 } }">

Then implementation of changeView is up to you, but I assume you would need to do something with $location.path to the change view:

$scope.searchProduct = function() {
  // ...
  ${query: $scope.query});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download