[英]How to disable check box per day and fetch the selected values using Angular.js?
[英]how can i grab all selected check box values on submit action using angular js?
当我选中复选框时,控制台出现错误。 我已附上屏幕截图。如何在提交事件中掌握所有选定的复选框值,以及如何避免无法分配为只读属性“ selected”错误
angular .module('test1') .controller('Test1Controller', [ '$scope', '$http', '$location', '$window', function($scope, $http, $location, $window) { var storeid = window.localStorage.getItem("storeid"); $http.get('***').success(function(data, status, response) { $scope.items = (JSON.stringify(data[0].D_Services).replace(/\\"/g, "")).split(','); console.log($scope.items); //console i'm getting ["Tyres", "Spares", "Accessories"] $scope.selected = []; }); $scope.check = function(data) { var arr = []; for (var i in data) { if (data[i].SELECTED == 'Y') { arr.push(data[i].item); } } console.log(arr); $scope.selected = arr; } } ]);
<div ng-controller="Test1Controller" data-ng-init="loadservice()"> <div ng-repeat="item in items"> <input type="checkbox" ng-model="item.selected" ng-true-value="'Y'" ng-false-value="'N'"/> {{item}} </div> <input type="button" name="submit" value="submit" ng-click="check(items)"/> </div>
您可以通过创建模式数据并将其附加到$ scope.items来实现此目的。
var serverData = ["Tyres", "Spares", "Accessories"]; //assuming this is server data
$scope.items = [];
for (var i = 0; i < serverData.length; i++) {
var modal = {
name: serverData[i],
selected: false
};
$scope.items.push(modal);
}
更新的jsFiddle: http : //jsfiddle.net/gopinathshiva/nLC3g/477/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.