2
美好的一天!我需要用ui-select在裏面創建指令。
這裏是指令的控制器和模板:angularjs ui-select創建自定義指令的麻煩
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;
});
};
}]);
<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}}
這裏是指令的初始化。
app.directive('services', function() {
return {
restrict: 'E',
templateUrl: window.baseurl + 'views/services',
scope: {
data: "=ngModel"
},
controller: "servicesCtrl",
controllerAs: "services"
}
});
<services ng-model="meEvent.services"></services>
無法從servicesCtrl呈現scope.data $眼簾編輯先前選定的數據。
$ scope.data中有一個對象,但爲空視圖的字段。我試過ng-model =「$ parent.data」和ng-model =「data」,但是沒有效果。
評論是不適用於擴展的討論;這個談話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/77809/discussion-on-question-by-nicollo-angularjs-ui-select-trouble-with-creating-cust)。 – Taryn