我正在阅读其他stackoverflow文章和更改代码,但我似乎无法理解这个
angular.module('app')
.controller('DefaultCtrl', ['$scope', function ($scope) { }])
工厂是问题
.factory('autoCompleteDataService', [function ($scope, $http) {
return {
getSource: function($scope) {
$http.get("GetPersonInfoFromRegister/T")
.success(function(data) {
$scope.countries = data;
});
}
这个指令很好,我试图修改工厂从静态返回的ajax调用返回数据
.directive('autoComplete', function (autoCompleteDataService) {
return {
restrict: 'A',
link: function (scope, elem, attr, ctrl) {
// elem is a jquery lite object if jquery is not present,
// but with jquery and jquery ui, it will be a full jquery object.
debugger;
elem.autocomplete({
source: autoCompleteDataService.getSource(), //from your service
minLength: 1
});
}
};
});
}
}])
当我使用示例并返回
时工厂正在工作return ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];