AngularJS$rootScope函数ng更改
AngularJS $rootScope function ng-change
html
<input type="text" data-search="type" placeholder="Search a Candidate, Job, Certificate or Location" ng-model="searchMain" ng-change="$root.updateSearchField(searchMain)"/>
上面是一个将作为实时搜索的输入字段,它被放入index.html
中,使用Angular-Route
我使用路由来加载页面。
角度
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log(current);
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
$scope.filterText = '';
// Instantiate these variables outside the watch
var tempFilterText = '', filterTextTimeout;
$rootScope.updateSearchField = function(foo) {
console.log($scope.searchMain);
if (filterTextTimeout) $timeout.cancel(filterTextTimeout);
tempFilterText = foo;
filterTextTimeout = $timeout(function() {
$rootScope.searchText = tempFilterText;
console.log($rootScope.searchText);
}, 250); // delay 250 ms
};
});
我看到的ng-change()
的函数应该在.run()
内部,但当我按下键时,仍然没有console.log()
返回。
如何运行ng-change
或单击from the
$rootScope`?
ng-change
接受一个参数,该参数是一个表达式。一旦输入值发生更改,表达式将在当前作用域的上下文中进行求值。这意味着,如果与当前元素关联的作用域(或其任何其他父作用域(没有$rootScope
属性,则您的代码段将不起作用。
试试这样的东西:
<input type="text" data-search="type" placeholder="Search a Candidate, Job, Certificate or Location" ng-model="searchMain" ng-change="updateSearchField()"/>
相关文章:
- ng更改事件不适用于Dropdown
- ng更改函数未被调用,并且没有错误
- 让ng更改等待$watch完成
- 如何使用AngularJS的ng更改
- 如何在ng重复中动态创建ng更改
- AngularJS触发ng更改不起作用
- 单击ng更改列表项的活动bg颜色
- 指令中的循环和ng更改Angular JS
- ng-更改以与以前的值进行比较
- 为预先选中的复选框在加载时运行ng更改函数
- Angular:$scope有效,但“;控制器为“;不触发ng更改事件
- ng更改后,从控制器重置ng模型值
- 在angularjs复选框输入中更新ng模型或执行ng更改之前需要确认
- 日期选择器的ng更改问题
- 在选择标记中的 ng 更改上重定向
- 自动检查单选按钮并执行 ng 更改
- 加载时触发 ng 更改
- ng更改无法使用单选按钮
- ng更改未从标签内的复选框中激发
- 单击ng更改JSON调用