AngularJS-Ng-route-输入时更改ng-view:focus [英] AngularJS - Ng-route - Change ng-view when input:focus

查看:93
本文介绍了AngularJS-Ng-route-输入时更改ng-view: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

推荐答案

所有您需要做的就是将ngChange指令与

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆