带有 jquery 自动完成功能的 Angularjs 不起作用 [英] Angularjs with jquery auto complete not working
本文介绍了带有 jquery 自动完成功能的 Angularjs 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
过去 5 个小时我一直在尝试但没有成功...这是代码..
I am trying for the past 5 hours without success... Here is the code..
在视图中:
<input type="text" ng-model="foo" auto-complete/>Foo = {{foo}}
在控制器中:
myapp.directive('autoComplete', function(autoCompleteDataService) {
return {
restrict: 'A',
link: function(scope, elem, attr, ctrl) {
elem.autocomplete({
source: autoCompleteDataService.getSource(), //from your service
select: function( event, ui ) {
scope.foo= ui.item.label;
scope.$apply;
},
change:function (event, ui) {
if (ui.item === null) {
scope.foo = null;
}
},
minLength: 2
});
}
};
});
myapp.factory('autoCompleteDataService', [function() {
return {
getSource: function() {
return ['apples', 'oranges', 'bananas'];
}
}
}]);
这里是问题...
所选项目进入输入框,但输入框旁边的 foo 变量没有更新.
The selected item is getting into the input box, but foo variable next to input box is not updating.
错在哪里.
请推荐...
推荐答案
更改
scope.$apply;
到
scope.$apply(function(){
scope.foo= ui.item.label;
});
这篇关于带有 jquery 自动完成功能的 Angularjs 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文