简体   繁体   English

在NgFor中调用组件-Angular

[英]Calling Components in NgFor - Angular

I'm trying to call dynamic components in ngFor, but i cannot use variables inside Tags HTML. 我正在尝试在ngFor中调用动态组件,但是我不能在Tag HTML中使用变量。

What i have: 我有的:

components = [component1, component2, component3];

<div *ngFor="let component of components">
  <component></component>
</div>

Result i want: 结果我想要:

<component1></component1>
<component2></component2>
<component3></component3>

Result i get: 结果我得到:

<component></component>
<component></component>
<component></component>

You won't be able to do it that way. 您将无法那样做。 You'll have to use the component loader: 您必须使用组件加载器:

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