[英]How to display dynamic components in angular 8+
I am new to Angular.我是 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. ps:在管理界面中,我有一个组件名称的“列表”,当他通过检查选择一个时,它将显示在用户界面中。
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.您可以使用
@Input() var1
和@Output() var 2
来输入/输出布尔值,然后使用*ngIf
指令在 HTML 中控制它。
Then in HTML, use [var1]
and (var2)
to Input/Output.然后在 HTML 中,使用
[var1]
和(var2)
来输入/输出。
Regards.问候。
You can either display your dynamic components via, template (using *ngIf
) or Programmatically (using ViewContainerRef
) Refer this article may help you.您可以通过模板(使用
*ngIf
)或以编程方式(使用ViewContainerRef
)显示您的动态组件,请参阅本文可能对您有所帮助。 https://dzone.com/articles/how-to-dynamically-create-a-component-in-angular https://dzone.com/articles/how-to-dynamically-create-a-component-in-angular
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.