I want to use an ng-click to get a piece of html. There is also an ng-click event in this html. I use js to find this piece of html and assign it to a pop-up layer. The ng-click event of this html is invalid. Okay, how to fix it?
$scope.readmore_maincomment = function(event){
var html = $(event.target).parent(".subcomments").prev().html();
$(".subcomments_detail").find(".subcomment_con").html(html);
};
The code is an abbreviation. It is the content obtained in this way. The method may be used wrongly, and angular and jQuery are mixed. Who can tell me how to obtain this html content, and then the ng-click in the html can also take effect
Angular will traverse the dom at the beginning of startup, find out all the directives bound in html, compile and link, and then instructions like `v-click` will bind response events to the dom elements where they are located. If you directly insert the HTML string into the DOM, Angular will have no chance to parse the instructions in this string of HTML. In order to solve this problem, angular’s built-in $compile service.
Usage:
inject $compile service
$compile(htmlstring or domelement)(scope)
If compile htmlstring finally insert the return after the link into the dom
$compile() return a link function which bind the template to a scope
Official website document:
The idea of angularjs should try to avoid operating DOM. Your needs should be realized through other ways, and your goals can be achieved through data binding, or you can use ng-template to do it.
The operations of DOM are all in the instructions. You have to write the DOM structure you currently want to operate as instructions, and then there is ele in the parameters of the link function for you to operate. The HTML you want to copy has ngclick. The same will take effect after copying.