我想在我的系统上运行下面的代码,但无法获得结果。但是我在运行的js fiddler上运行相同的代码。与angularjs不工作的搜索建议功能
这是我的index.html
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-app>
<div ng-controller="MyController">
<input type="search" ng-model="search" placeholder="Search...">
<ul>
<li ng-repeat="name in names | filter:search">
{{ name }}
</li>
</ul>
</div>
</div>
的script.js
var app = angular.module('MyModule', []);
app.controller('DefaultCtrl', function($scope) {
$scope.names = ["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"];
});
app.directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
iElement.autocomplete({
source: scope[iAttrs.uiItems],
select: function() {
$timeout(function() {
iElement.trigger('input');
}, 0);
}
});
};
});
我也想,如果我输入 'A' 只有一行字来是先从字母“获得exaxct比赛A”等等......
它给出一个错误TypeError:iElement.autocomplete不是一个函数 –
我不确定它是否相关,但在HTML和JS文件中的ng-controller名称ar不同。 – Sid