【发布时间】:2021-01-02 09:36:18
【问题描述】:
我正在尝试在前端显示每个部分的子部分,但不知道如何做,所以如果我能得到任何帮助或建议,我将不胜感激。
我的数据库中有两个表部分和子部分。
Section 表有 Id 和 Section Name。
子节表有 Id、ParentId(节表 ID 的外键)、子节名称和文本。
在我的前端 http 服务中,我有两种获取方法(一种用于部分,另一种用于子部分)
Services.ts
getHelpSection() {
return this.http.get<HelpSection[]>(`${environment.api.chart}/helpSection`).pipe(first());
}
getHelpSubsection() {
return this.http.get<SubSection[]>(`${environment.api.chart}/helpSubsection`).pipe(first());
}
组件.ts
Constructor(private HelpService: HelpService) {}
helpSection: {[key: string]: HelpSection } = {};
helpSection$ = this.HelpService.getHelpSection();
helpSubsection$ = this.HelpService.getHelpSubsection();
组件.html
<mat-nav-list>
<mat-expansion-panel class="exp-panel" *ngFor= "let help of helpSection$ | async">
<mat-expansion-panel-header style="align-items: center;">
<div >{{help.sectionName}}</div>
</mat-expansion-panel-header>
<a mat-list-item (click)="clicked()">Here it will display subSection Name for each sections</a>
</mat-expansion-panel>
</mat-nav-list>
现在看起来像这样。
【问题讨论】:
标签: angular typescript api get rendering