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);    
    }
}


0 comments:

Blogroll

Follow this blog by Email

Popular Posts