简体   繁体   English

如何使用 TypeScript 函数在 body 中动态添加组件

[英]How to add a component dynamically in the body using TypeScript function

I want to add dynamically components tag to my page using a TypeScript function.我想使用 TypeScript 函数将组件标签动态添加到我的页面。

Something like putThisComponentToBody(MyAngularComponent) , that would append <app-my-angular-component></my-angular-component> to my DOM.putThisComponentToBody(MyAngularComponent)这样的东西,会将<app-my-angular-component></my-angular-component>附加到我的 DOM。

Excepted result in DOM : DOM 中的异常结果:

To add components dynamically at run time you will have to use some container which will be used to attach your component.要在运行时动态添加组件,您必须使用一些用于附加组件的容器。 Please go through this link - https://angular.io/guide/dynamic-component-loader请通过此链接 - https://angular.io/guide/dynamic-component-loader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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