.directive("checkboxsGroup", function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
// Determine initial checked boxes
if (scope.arrays.indexOf(scope.item.value) !== -1) {
elem[0].checked = true;
}
// Update array on click
elem.bind('click', function() {
var index = scope.arrays.indexOf(scope.item.value);
// Add if checked
if (elem[0].checked) {
if (index === -1) scope.arrays.push(scope.item.value);
}
// Remove if unchecked
else {
if (index !== -1) scope.arrays.splice(index, 1);
}
// Sort and update DOM display
/* scope.$apply(scope.array.sort(function(a, b) {
return a - b
}));*/
});
}
}
})
**my html code**
<div ng-repeat="colors in frame_product_options.color_list">
<input type="checkbox" checkboxs-group />{{colors.color_name}}
<input type="button" name="Save" class="btn btn-success btn-sm" ng-click="frame_color_img(colors.id)" value="Save">
</div>
<input type="hidden" name="clrcheckboxvalues" ng-model="frame.clr_code" ng-init="frame.clr_code=arrays">
答案 0 :(得分:0)
您收到未定义错误的原因是,您没有在指令的范围内定义scope.arrays
。例如,如果您在控制器范围内定义scope.arrays
,则错误将消失。