Here's Angular 1.21 solution:
HTML:
<div ng-app="app" ng-controller="ctrl"> <div ng-iff="checked" id="div1"> <div id="div2">ABC</div> <div id="div3">KLM</div> <div id="div4">PQR</div> </div> <button ng-click="toggleCheck()">Toggle Check</button> </div>
JAVASCRIPT:
angular.module('app', []). controller('ctrl', function ($scope) { $scope.checked = true; $scope.toggleCheck = function () { $scope.checked = !$scope.checked; }; }). directive('ngIff', function ($compile) { return { compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { var bindingElem = iElement.attr('ng-iff'); var children = iElement.children(); angular.forEach(children,function(c){ angular.element(c).attr('ng-if',bindingElem); }); $compile(children)(scope, function(newElem){ iElement.replaceWith(newElem); }); } }; } }; });
JSFIDDLE .
Amir Popovich Jun 12 '15 at 4:45 2015-06-12 04:45
source share