var app = angular.module('plunker', []);
app.controller('testController', function($scope) {
//default states
$scope.selectDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
$scope.selectedList = {};
/**
* Action
*/
$scope.submit = function () {
angular.forEach($scope.selectedList, function (selected, day) {
if (selected) {
console.log(day);
}
});
};
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
<script src="app.js"></script>
</head>
<body ng-controller="testController">
<span ng-repeat="day in selectDays">
<input type="checkbox" id="{{day}}" ng-model="selectedList[day]"/>
<label for="{{day}}">{{day}}</label>
</span>
<button ng-click="submit()">Submit</button>
<h2>Selected</h2>
<p>{{selectedList|json}}</p>
</body>
</html>
/* Put your css in here */