You can use ng-repeat + ng-model over an array of parameters.
HTML
<body ng-controller="MainCtrl"> <div class="container"> <h1>Options</h1> <div> <div class="form-group" ng-repeat="option in options"> <label>{{option.name}}</label> <input type="checkbox" ng-model="option.value"> </div> </div> <hr> <button class="btn btn-primary" ng-click="save()">save to database</button> </div> </body>
Js
var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.options = [{ name: 'java', value: true, }, { name: 'c#', value: false }, { name: 'angular', value: true }, { name: 'r', value: false }, { name: 'python', value: true }, { name: 'c++', value: true }]; $scope.save = function() { var optionsCSV = ''; $scope.options.forEach(function(option) { if (option.value) {
source share