AngularJS-Ng-route-输入时更改ng-view:focus [英] AngularJS - Ng-route - Change ng-view when input:focus
问题描述
我想用ng-view改变我的看法.关键是,当有人开始在input:text
字段中键入内容时,我需要执行此操作,而不是触发ng-click
事件(因此,与在此页面).
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:我尝试将ng-click
添加到输入元素,但这不会触发事件.任何帮助将非常感激.谢谢!
PS: I tried adding ng-click
to the input element, but that doesn't trigger the event. Any help would be much appreciated. Thanks!
这是更新的 plunkr ,其中包含dfsq提供的正确答案>
Here is the updated plunkr with the correct answer provided by dfsq
推荐答案
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 } }">
然后changeView
的实现由您决定,但是我认为您需要对更改视图使用$location.path
进行一些操作:
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});
};
这篇关于AngularJS-Ng-route-输入时更改ng-view:focus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!