Joe82 Joe82 - 10 months ago 52
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!


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});