Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="App" ng-controller="TestController">
<div>
  <ul>
    <li ng-repeat="item in data"> {{ item.name }}--{{ item.status }}---<button ng-click="changeStatus(item.id)">change</button></li>
  </ul>
</div>
</body>
</html>
 
var App = angular.module("App", []);
App.controller('TestController', function ($scope) {
  $scope.data = [
    {id:1, name: 'cc', status: true},
    {id:2, name: 'bob', status: false}
  ];
  $scope.changeStatus = function (id){
    angular.forEach($scope.data, function (item) {
      if (item.id === id){
        item.status = !item.status;
      }
    });
  };
  $scope.$watch('data', function (){
    console.log('has changed');
  }, true);
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers