我有一个带有下拉列表的角度应用程序:使用bootstrap multiselect进行多个选择和单个选择,我的问题是,当我在页面中有任何选择标记时,它会自动呈现为多个并获得错误消息。
var app = angular.module("myApp", ["ui.bootstrap"]);
app.directive('multiSelect', function () {
function link(scope, element) {
element.multiselect();
}
return {
restrict: 'A',
link: link
};
});
app.config(['$provide', function ($provide) {
$provide.decorator('selectDirective', ['$delegate', function ($delegate) {
var directive = $delegate[0];
directive.compile = function () {
function post(scope, element, attrs, ctrls) {
directive.link.post.apply(this, arguments);
var ngModelController = ctrls[1];
if (ngModelController && attrs.multiSelect !== null) {
originalRender = ngModelController.$render;
ngModelController.$render = function () {
originalRender();
element.multiselect('refresh');
};
}
}
return {
pre: directive.link.pre,
post: post
};
};
return $delegate;
}]);
}]);
这就是我收到的错误消息:
TypeError: Cannot read property 'prop' of undefined
at Multiselect.<anonymous>
并选择:
<select ng-model="selection" class="form-control" ng-options="x.Code as x.Description for x in Types track by x.Code" multiple="multiple" multi-select></select>