我正尝试使用Angular multiselect指令(具体为isteven/angular-multi-select)作为多选接口组件。它的问题在于它返回的数据是全部选定对象的数组,而我们宁愿使用对象的简化版本(例如ID数组)。由于这个组件已经被我们自己的抽象指令包装了,所以我想找到一些方法来拦截子范围值,因为它正在被修改,然后通过我的包装指令中的ngModel范围属性返回那个减少的值。如何包装/截取角度范围值
指令定义
angular.module('cw-ui').directive('cwSelect', function() {
return {
scope: {
ngModel: '=',
options: '=',
maxLabels: '@?',
selectionMode: '@?',
onClose: '&'
},
templateUrl: 'UI/Directives/select',
compile: function(element, attributes) {
if(attributes.maxLabels === undefined) {
attributes.maxLabels = 3;
}
}
};
});
包装指令模板
<isteven-multi-select input-model="options" output-model="ngModel" button-label="icon name" item-label="icon name maker" tick-property="ticked" group-property="msGroup" max-labels="{{::maxLabels}}" selection-mode="{{selectionMode}}" on-close="onClose()"></isteven-multi-select>
如果您发布的指令是针对您发布的html元素,那么不应该使用名为istevenMultiSelect的指令或元素具有attr cw-select? – micha 2015-03-31 14:22:05
啊,对不起,应该更清楚的是我发布了包装指令的模板。我会编辑我的帖子来澄清。 – moberemk 2015-03-31 14:31:46