Angularjs Append Html In The Ng-repeat Element
Using AngularJS I need to append HTML to the elements of ng-repeat, using the selector: 'objectMapParent-' + post._id
Solution 1:
How to Encapsulate jQuery code in a Custom Directive
Any jQuery code that manipulates the DOM should be encapsulated in a custom directive so that it is executed when the AngularJS framework ng-repeat directive instantiates the element.
<divng-repeat="post in posts"><divid="{{ 'objectMapParent-' + post._id }}"><h5style="color:blue; margin-top: 3px;">{{post.title}}</h5><my-elementpost="post"></my-element></div></div>
app.directive("myElement", function() {
return {
link: postLink,
};
function postLink(scope,elem,attrs) {
var post = scope.$eval(attrs.post);
var html = `
<div id="objectMap-${post._id}">
<div id="BasemapToggle-${post._id}">
</div>
</div>
`;
elem.append(html);
}
})
To use jQuery, simply ensure it is loaded before the angular.js
file.
For more information, see
Post a Comment for "Angularjs Append Html In The Ng-repeat Element"