jeudi 13 août 2015

Change an array depend on check/uncheck checkbox

I want to change columns: [...] depend on checkbox.

If I check the checkbox then it should give me columns: ['model.name' ,'model.department']

and when I uncheck it should change it to columns: ['model.name'] - removed model.department

angular.module('plunker', [])

.controller('MainCtrl', function($scope) {
  $scope.options = {
    columns: ['model.name', 'model.department'],
  };
});
<script src="http://ift.tt/1mQ03rn"></script>
<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script data-require="angular.js@1.*" data-semver="1.4.3" src="http://ift.tt/1g2WAJw"></script>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <link rel="stylesheet" href="style.css" />
  <script src="app.js"></script>
</head>



<body ng-controller="MainCtrl">
  <li>
    <label>
      <input type="checkbox" ng-model=options.columns>Department</label>
  </li>
</body>

</html>



Aucun commentaire:

Enregistrer un commentaire