2014-09-20 65 views
1

我創建了一個plunker代碼這個問題在這裏http://plnkr.co/edit/mTaRPoAsQQQ6OSEQLS3a?p=previewChosen.js不與角指令

這很好地工作是列表

<select ng-model="modSelectedState" id="inputLocation-" name="filter_location"  
    class="location" ng-options="state as state.full_name for state in states" 
    chosen="states"> 
<option value="">State</option> 

的HTML代碼,你可以看到我創建了一個指令並將其命名爲「selected」,這裏是代碼:

app.directive('chosen', function ($http) { 
var linker = function (scope, element, attr) { 
    scope.$watch(scope.states, function (oldVal, newVal) { 
     element.trigger('liszt:updated'); 
    }); 
    scope.$watch(attr.ngModel, function() { 
     element.trigger('liszt:updated'); 
    }); 
    element.chosen({disable_search_threshold: 20}); 
}; 

return { 
    restrict: 'A', 
    link: linker 
} 
}); 

請注意,我使用的'選擇'的舊版本,需要'liszt:更新'而不是'選擇:更新'

我知道國家正在填充,因爲當我檢查代碼時,我可以看到他們在原來的SELECT中。有任何想法嗎?

+0

你是否注意到你在控制檯上的錯誤?這是說錯誤:[$ compile:multidir]要求'ngModel'控制器的多個指令[ngModel,ngModel]: