如何创建通用TemplateRef,然后将其作为对象参数传递给其他组件?

时间:2020-09-18 11:24:06

标签: javascript html angular ng-template

我有这样一个问题:我从api接收数据,然后基于该数据生成首饰数据。我必须传递给自己的网格组件的参数之一是基于特定数据的TemplateRef类型。问题是可能有很多记录,所以我需要为每个记录制作TemplateRef

因此在html中,我有示例模板:

<ng-template #someTemplate>
 <app-some-component [param1]=... [param2]=...></app-some-component>  <- params depends on received data
</ng-template>

在组件中,我有:

@ViewChild('someTemplate', {static: true}) someTemplateContent: TemplateRef<any>;

因此,基本上我想为数据数组的每个对象创建someTemplateContent,然后将其作为对象参数传递。我该怎么办?我需要更改模板中的某些内容吗?我是在模板上使用ngFor吗?

0 个答案:

没有答案
相关问题