Ng-Checked-5

 

Example of Ng-Checked:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="checkedExample"> <div ng-controller="ExampleController"> <div class="container"> <div ng-repeat="item in items"> <b>{{item}}</b> <span ng-if="isExists(item)" style="color:lightgreen">selected</span> </div> <hr /> <div ng-repeat="item in items"> <input type="checkbox" ng-checked="isExists(item)" ng-click="toggle(item)" /> {{item}} </div> <input type="checkbox" ng-checked="selected.length >= 2" ng-disabled="true">Two or more items selected <span>Selected: {{ selected }}</span> </div> </div> <script> var app = angular.module("checkedExample", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.items = ["AngularJs", "Bootstrap", "JQuery", "LearnIt", "javaScript"]; $scope.selected = []; $scope.toggle = function (item) { var idx = $scope.selected.indexOf(item); if (idx > -1) $scope.selected.splice(idx, 1); else $scope.selected.push(item); }; $scope.isExists = function (item) { return $scope.selected.indexOf(item) > -1; }; }]); </script> </body> </html>
Output