javascript - How do i select/replace element components by css classes inside a link function? -


i have been trying select , replace specific element in directive template has class .placeholder. have tried using replacewith() error saying not function. how select/replace element components css classes inside link function?

here code:

var comments = function($compile){   return {     templateurl : 'modules/comments/commentsdirective.html',     restrict:'e',     scope:{       collection: '='     },      link: function(scope, element, attrs){         if(scope.collection.data.replies){           var elementresult = element[0].getelementsbyclassname('placeholder');           console.log(elementresult); //works fine             //throws error here:***           elementresult.replacewith($compile('<ul ng-repeat="comment in collection.data"><comments collection="comment"></comments></ul>')(scope));          }     }   }; }; 

to call jqlite function replacewith(), need wrap our raw selector angular.element(). per angular.element docs...

wraps raw dom element or html string jquery element.

observe following change...

var elementresult =        angular.element(element[0].getelementsbyclassname('placeholder')); 

Comments