AngularJS supports append, prepend jQuery functionality. AngularJS append or prepend works exactly like as jQuery. Whenever we append HTML element, we have to compile that HTML element, then only angular events will work.

Steps to append html :

  1. Get angular element of div
  2. Use .append() method to append html to that angular element
  3. The below example creates one button with event.
function myCtrl($scope, $compile) {
    $scope.AppendText = function() {
     var myEl = angular.element( document.querySelector( '#divID' ) );
     var dir = angular.element('<button ng-click="AppendText()">Appended Button</button><br/>');
     myEl.append(dir);
     $compile(dir)($scope);    
    }
}


1 comment:

  1. Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
    Angularjs course in chennai

    ReplyDelete

Blogroll

Popular Posts