2015-05-14 65 views
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”,但是没有效果。

+0

评论是不适用于扩展的讨论;这个谈话已经[转移到聊天](http://chat.stackoverflow.com/rooms/77809/discussion-on-question-by-nicollo-angularjs-ui-select-trouble-with-creating-cust)。 – Taryn

回答

0

有我的版本的ui选择库中的错误