I am trying to improve several conditions using ng-show and ng-hide using directives, here is my code
html code
<my-directive controls="a,b,c"></my-directive>
js code
.directive('myDirective',function(){ return{ restrict:'E', templateUrl:"parentHtml.html", link:function(scope,elem,attr){ var options = attr.controls; if(options=="a,b,c"){ scope.showMeAll=true; }else if(options=="a"){ scope.showmeA=true; }else if(options=="b"){ scope.showmeB=true; }else if(options=="c"){ scope.showmeC=true; } } } }).directive('subDirective',function(){ return{ restrict:'E', template:"<h2>aapple</h2>", link:function(scope,elem,attr){ } } }).directive('subDirective1',function(){ return{ restrict:'E', template:"<h2>BBatt</h2>", link:function(scope,elem,attr){ } } }).directive('subDirective2',function(){ return{ restrict:'E', template:"<h2>CCat</h2>", link:function(scope,elem,attr){ } } });
here is my parentHtml.html code
<div class="row"> <div ng-show="showMeAll"> <sub-directive></sub-directive> </div> <div ng-show="showMeB"> <sub-directive1></sub-directive1> </div> <div ng-show="showMeC"> <sub-directive2></sub-directive2> </div> </div>
My problem is that I pass all three attributes โa, b, cโ to the directive attribute and then to โparentHtmlโ all three divs should show if I give only two, that is, โa, bโ and then in parentHtml, only two divs should show, for example, โappleโ and โbatโ, and also give only one line, that is, โcโ, and then in parentHtml only โcatโ div should show, in a simple way, if which alphabet I give the directive the attribute thet div should be displayed. Here is my http://plnkr.co/edit/6gAyAi63Ni4Z7l0DP5qm?p=preview . Please resolve my question in a simple way.
Thanks in advance