美好的一天!我需要使用ui-select inside创建指令。
这是指令的控制器和模板:
app.controller("servicesCtrl", ["$resource", '$scope', function($resource, $scope){
$scope.clinicServices = [];
console.log($scope.data);
var Services = $resource(window.baseurl + "services/getAllbyClinic", null, {
get:{responceType: "JSON", isArray: false, method: 'POST'}
});
$scope.refresh = function(service){
if(service.length < 1) return false;
Services.get({service: service},function(data){
$scope.clinicServices = data.services;
});
};
}]);
&#13;
<ui-select
multiple
tagging
tagging-label="false"
ng-model="$parent.data"
theme="bootstrap"
title="Выберите услугу"
search-enabled="true"
>
<ui-select-match placeholder="Введите услугу">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="clinicService in clinicServices" refresh="refresh($select.search)">
<div ng-bind-html="(clinicService.name | highlight: $select.search)"></div>
</ui-select-choices>
</ui-select>
{{data}}
&#13;
这是指令初始化。
app.directive('services', function() {
return {
restrict: 'E',
templateUrl: window.baseurl + 'views/services',
scope: {
data: "=ngModel"
},
controller: "servicesCtrl",
controllerAs: "services"
}
});
&#13;
<services ng-model="meEvent.services"></services>
&#13;
无法从servicesCtrl将$ scope.data渲染到视图中以编辑以前选择的数据。
$ scope.data中有一个对象,但是空视图的字段。我试过ng-model =&#34; $ parent.data&#34;和ng-model =&#34;数据&#34;,但没有效果。
答案 0 :(得分:0)
我的ui-select库版本中出现错误