Ng-Show-Ng-Hide-2

 
In this example we have an array named colors with color name and value. We show the checkbox for each color using ng-repeat directive and bind the checkbox with the color value either true or false. If the value is true then checkbox is checked and a box with background color shows and if value is false then checkbox is un-checked and color box will not show.
 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="Demo"> <div class="row" ng-controller="myController"> <div class="col-md-3" ng-repeat="color in colors"> <input type="checkbox" ng-model="color.val" /> {{color.colorName}} <div class="check-element animate-show" ng-show="color.val" style="background-color:{{color.colorName}};height:20px;width:20px;"></div> </div> </div> <script type="text/javascript"> var demo = angular.module("Demo", []); demo.controller("myController", function ($scope) { $scope.colors = [{ colorName: "pink", val: true }, { colorName: "green", val: false }, { colorName: "Red", val: true }, { colorName: "Yellow", val: true }] }); </script> </body> </html>
Output