How To Append A Dynamic Div In Angularjs?
.directive('mydirective', [function($scope, $document,windowService) { return{ link : function(scope,element,attars){ --- Some more code —-- var containers =
Solution 1:
Try with this
containers.bind('click', function (event) {
var elem = event.currentTarget;
$(elem).append('<div>test</div>’); //Appending should work
}
as elem
can be the HTML input object you have to convert it into jQuery object to use .append()
method of jQuery! so wrap your elem
variable arround $()
. It should work
Solution 2:
Better to use this. Removes dependency to JQuery as Angular core only use JQLite. It is basically the same thing that happens. https://docs.angularjs.org/api/ng/function/angular.element
containers.bind('click', function (event) {
var elem = event.currentTarget;
angular.element(elem).append('<div>test</div>’); //Appending should work
}
Post a Comment for "How To Append A Dynamic Div In Angularjs?"