Angularjs can be initiated by Ng-app from the dynamic initialization module or by Angular.bootstrap (document, [module]), regardless of the method, the DOM element that is dynamically added to the DOM tree after the application starts. Cannot execute the angular instruction, that is, how can I bind data and events to dynamically added DOM elements through Ng-model, Ng-click?
Dynamic add DOM elements of the scene is very common, such as clicking on a page to modify the user Information button, send an AJAX request to query the user information, and then through the template engine will be written in the page in advance of the static template into an HTML string, and finally the HTML string append to the page display, In general we would do this:
Click the Modify Data button, the newly inserted DOM element does not bind the Ajax returned data, because the angular has been initialized before clicking the button, the solution is not to initialize it once, but to use $compile to compile the HTML of the static template alone. Then insert the
in the DOM tree
The above is about ANGULARJS initialization static template detailed introduction, I hope to help you learn.