Angular: Empty Fiddle

http://angularjs.org/

by Diego Augusto

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div class="panel" ng-controller="MyCtrl">
   <div ng-repeat="profile in dbProfiles">
      <div class="action-checkbox">
         <input id="{{profile.nome}}" type="checkbox" value="{{profile}}" ng-checked="selection.indexOf(profile) > -1" ng-click="toggleSelection('profile: '+profile.id)" />
         <label for="{{profile.nome}}"></label>
         {{profile.nome}}
      </div>
   </div>
   <span style="color:black;" class="selected-item">Selected Items:<span>
   {{selection|json}}

JavaScript

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


function MyCtrl($scope) {
$scope.dbProfiles = [{
        id:1,
        nome:"Adminstrador"
    },
    {   id:2,
        nome:"Tabeliao"
    },
    {   id:3,
        nome:"Substituto"
    },
    {   id:4,
        nome:"Escrevente"
    },
    {   id:5,
        nome:"Caixa"
    },
    {   id:6,
        nome:"Auxiliar"
    }
];
 
$scope.selection = [];
$scope.toggleSelection = function toggleSelection(profile) {
    var idx = $scope.selection.indexOf(profile);

    if (idx > -1) {
        $scope.selection.splice(idx, 1);
    }
    else {
        $scope.selection.push(profile);
    }
};
}