mardi 5 juillet 2016

Angularjs + Check Checkbox clicked or not

I am using angularjs. I have sample list of json. I am display the list using ng-repeat and I have checkbox in html. I need to find user checkbox is clicked or not(not checked or not).

I added my code.

app.js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
   $scope.result = {};
  $scope.result.name = 'World';
  var data = '[ { "button": 1, "name": "Test-1", "checked" : 0 }, { "button": 2, "name": "Test-2", "checked" : 0 }, { "button": 3, "name": "Test-3", "checked" : 1 }, { "button": 4, "name": "Test-4", "checked" : 0 }, { "button": 5, "name": "Test-5", "checked" : 1 } ]';

    $scope.result.list = JSON.parse(data);

});

index.html:

  <body ng-controller="MainCtrl">
    <p>Hello !</p>
    <ul>
      <li ng-repeat="list in result.list"> 
      <input type="checkbox" ng-model="list.isChecked" ng-checked="list.checked == 1"> -  </li>
    </ul>
  </body>

Please check this link - click here

Expected output:

Find user clicked the checkbox or not. If checkbox already checked (3 & 5). If user unchecked means I need to identify.




Aucun commentaire:

Enregistrer un commentaire