Explanation: the ng-click solution in the page dynamically generated by angularJS is invalid. angularjsng-click
Today, I met this requirement. On the dynamic page written by myself, AngularJS is invalid and cannot click to respond to events. The following code and solutions are provided:
1. First, assign a value to the data on the page.
Var html = "<a href = 'javascript: void (0); 'ng-click = 'test () '> </a>"
2. Use the $ compile function to compile the above content
Var $ html = $ compile (html) ($ scope );
3. Insert compiled content into the page
$ ("Body"). append ($ html );
Complete
The complete version is as follows:
App. controller ('mermersctrl', function ($ scope, $ http, $ compile) {$ scope. test = function () {alert ('test ');} // TODO Dynamic html ng-click is invalid solution $ compile is passed in // The following sentence is to write the content on the page, first, assign the value of the content you write to html var html = "<a href = 'javascript: void (0); 'ng-click = 'test () '> </a> "// use $ compile to compile var $ html = $ compile (html) ($ scope); // Add it to the page, or any location you want to add .}); $ ("Body"). append ($ html );
In this way, ng-click can trigger the function.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.