问题
I would like to change my view with ng-view. The point is that instead of firing an ng-click
event, I would need to do it when somebody starts typing in an input:text
field (so I could achieve the same effect as when start typing in the search box in this page).
PS: I tried adding ng-click
to the input element, but that doesn't trigger the event. Any help would be much appreciated. Thanks!
Edit: Here is the updated plunkr with the correct answer provided by dfsq
回答1:
All you need to do is to use ngChange directive with ngModelOptions (for debounce):
<input type="text"
ng-change="searchProduct()"
ng-model="query"
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() {
// ...
$location.search({query: $scope.query});
};
来源:https://stackoverflow.com/questions/37511072/angularjs-ng-route-change-ng-view-when-inputfocus