【发布时间】:2023-03-22 07:35:01
【问题描述】:
我正在尝试设置这样的动态扩展面板:
<mat-accordion>
<mat-expansion-panel *ngFor="let category of categories">
<mat-expansion-panel-header>
<mat-panel-title>
{{category.name}}
</mat-panel-title>
</mat-expansion-panel-header>
<ng-template #category>
<a>Test</a>
</ng-template>
<mat-action-row>
<button mat-button color="primary" (click)="nextStep()">Next</button>
</mat-action-row>
</mat-expansion-panel>
</mat-accordion>
在我的组件中,我尝试像这样访问每个模板:
@ViewChildren('category') components: QueryList<CategoryDirective>;
和
ngAfterViewInit() {
const viewContainerRef = this.adHost;
if (!_.isUndefined(this.categories) && !_.isUndefined(this.components)) {
this.components.changes.subscribe(() => {
this.components.toArray().forEach(el => {
console.log('ngAfterViewInit', el);
});
});
}
}
对于每个类别,我都有一个要加载到 ngTemplate 中的组件属性。
我该怎么做?
【问题讨论】:
标签: angular angular-material angular-directive