简体   繁体   中英

can i load an angular 2 component into DOM from javascript?

 function injectAngular (){ console.log("angular"); document.body.innerHTML += '<app-root style="height:100%;width:100%"></app-root>' } 
 <button type="button" onclick="injectAngular()" name="button">angular</button> 

when i tried this approach angular was not able to recognize the selector . Is there a solution to solve this problem .

Instead of touching the InnerHTML directly, why not set up a view (using an ng-repeat element) that gets its values from a JSON value in your controller? You can very easily add new elements that way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM