gpt4 book ai didi

AngularJS 在自定义指令中包装 ui-select

转载 作者:行者123 更新时间:2023-12-04 10:37:36 26 4
gpt4 key购买 nike

我正在尝试将 ui-select 包装在自定义指令中。 (https://github.com/angular-ui/ui-select)

this.adminv2.directive('eventSelect', function() {
return {
restrict: 'E',
replace: true,
scope: {
ngModel: '=',
placeholder: '='
},
controller: function($scope, $http) {
return $scope.refreshEvents = function(searchTerm) {
return $http.get('/events/autocomplete', {
params: {
term: searchTerm
}
}).then(function(response) {
return $scope.events = response.data;
});
};
},
template: "<div>{{ngModel}}\n <ui-select ng-model=\"ngModel\"\n theme=\"bootstrap\"\n ng-disabled=\"disabled\"\n reset-search-input=\"false\">\n <ui-select-match placeholder=\"Enter an event\">{{$select.selected.name}}</ui-select-match>\n <ui-select-choices repeat=\"event in events track by $index\"\n refresh=\"refreshEvents($select.search)\"\n refresh-delay=\"0\">\n <span ng-bind-html=\"event.name | highlight: $select.search\"></span>\n <i class=\"icon-uniF111 fg type-{{raceType}} pull-right\" ng-repeat='raceType in event.racetypes'></i>\n <br>\n {{event.dates}} <i class='pull-right'>{{event.location}}</i>\n </ui-select-choices>\n </ui-select>\n</div>"
};
});

选择正常工作,但与 ng-model 的绑定(bind)不起作用。我无法设置模型或读取它。
我不明白,因为当我使用简单的模板时它可以工作,例如
<div><input ng-model="ngModel"></div>

因为我在指令中包装了指令,所以有什么特别的事情要做吗?

最佳答案

我设法通过将模板中的 ng-model 设置为

ng-model="$parent.ngModel"

关于AngularJS 在自定义指令中包装 ui-select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26647530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com