我已创建指令以使用自定义自动填充功能。
app.directive('autocomplete', function () {
return {
restrict: 'E',
scope: {
results: '=',
getStrLength: '&',
selectObj: '&'
},
templateUrl: 'shared/js/angular/directives/templates/autocomplete.html'
};
});
这里是指令
的视图<input class="custom-autocomplete" ng-model="keyword" ng-keyup="getStrLength({word: keyword})" type="text" />
<div id='custom-autocomplete' ng-if="results" >
<div class="object" ng-repeat="(country, groups) in results.value">
<b class='flags flag_{{country| lowercase}}'></b>{{results.countries[country]}}
<div class='object-first-level' ng-click="selectObj({obj: group})" ng-repeat='(city, group) in groups'>
{{group.name}}
</div>
</div>
</div>
&#34; selectObj&#34;函数执行$ scope.keyword已更新,但在指令模板
中没有更改这是从控制器点击的功能
$scope.selectObj = function (obj) {
$scope.autocompleteReusuls = '';
$rootScope.keyword = obj.name;
}