使用jQuery自动完成Angularjs不工作 [英] Angularjs with jquery auto complete not working
本文介绍了使用jQuery自动完成Angularjs不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在过去的5个小时没有成功...
这里是code ..
I am trying for the past 5 hours without success... Here is the code..
在View:
<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屋!
查看全文