【发布时间】:2014-06-02 10:28:12
【问题描述】:
我正在使用 jQuery 自动完成功能开始为输入文本的用户填写值。
<input type="text" ng-model="tags" name="tags" id="tags" value="" />
稍后我的 ng-repeat 会根据该文本过滤内容
<div ng-repeat="ability in abilities | tagsFilter:tags">
{{ ability }}
</div>
在 jQuery 自动完成内部,当用户从自动完成下拉菜单中选择一个项目时,有一个回调函数。
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
// I Want to tell angularJS to update
return false;
}
我如何告诉我的 ng-repeat 更新?
我尝试查看 $scope.apply() 但 $scope 不在 jQuery 回调的范围内。
【问题讨论】:
-
你不能只创建一个指令吗?看看这个:angular-ui.github.io/bootstrap/#/typeahead
-
呃,这个不要用jQuery,Angular有很多替代品,AngularStrap很有用!
-
我同意这些人的观点,但如果您确实希望它工作,您可能只需要调用 $scope.$apply()。 jQuery 是在 Angular 范围之外执行的,所以它不知道要更新。
标签: javascript jquery angularjs angularjs-ng-repeat