简体   繁体   中英

How to display dynamic components in angular 8+

I am new to Angular. I am working on a project where I want the administrator choose which components will be displayed to the user.

ps: In the admin interface, I have a "list" of components'names and when he choose one by checking it, it will be displayed in the user interface.

How Can I do this please?

You can use @Input() var1 and @Output() var 2 to Input/Output a boolean and then control it in HTML using the *ngIf directive.

Then in HTML, use [var1] and (var2) to Input/Output.

Regards.

You can either display your dynamic components via, template (using *ngIf ) or Programmatically (using ViewContainerRef ) Refer this article may help you. https://dzone.com/articles/how-to-dynamically-create-a-component-in-angular

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