【发布时间】:2014-09-20 21:02:00
【问题描述】:
我在这里为这个问题创建了一个 plunker 代码 http://plnkr.co/edit/mTaRPoAsQQQ6OSEQLS3a?p=preview
这是列表的 HTML 代码
<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>
如你所见,我创建了一个指令并将其命名为“选择”,代码如下:
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
}
});
请注意,我使用的是旧版本的 'chosen',它需要 'liszt:updated' 而不是 'chosen:updated'
我知道状态正在被填充,因为当我检查代码时,我可以在原始 SELECT 中看到它们。有什么想法吗?
【问题讨论】:
-
您是否注意到控制台出现错误?它说错误:[$compile:multidir] 多个指令 [ngModel, ngModel] 要求在:
-
@WebDever 是的。它与第二个指令有关。我已将其删除以避免混淆。该指令仍然无效。
标签: javascript jquery angularjs jquery-chosen