i have button on click of want keep adding divs children parent div.i want in angularjs.could some1 please give me example of how achieve this?i don't know if matters dynamic child div trying add has ng-include in it. <button ng-click="callme()"> add dynamic divs </button> <div class="parentdiv"> </div>
the dynamic div want add parentdiv on click follows: <div ng-include="/xyz.html"></div>
ng-show or ng-if guess not work hwre since wnat user able add many child divs clicks make right? if case, use directives accomplish task:
//directive adding divs myapp.directive("adddivs", function($compile){ return function(scope, element){ element.bind("click", function(){ angular.element(document.getelementbyid('space-for-buttons')).append($compile("<div ng-include='/xyz.html'></div>")(scope)); }); }; }); //directive returns element adds divs myapp.directive("adddiv", function(){ return { restrict: "e", template: "<button adddivs>click add div</button>" } });
and in partial:
<section ng-app="myapp" ng-controller="mainctrl"> <adddiv></adddiv> <div id="space-for-buttons"></section> </section>
Comments
Post a Comment