【问题标题】:How to get subsection for each section in angular如何以角度获取每个部分的小节
【发布时间】: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


    【解决方案1】:

    this.HelpService.getHelpSection().subscribe(res => { this.helpSection$ = res });

    【讨论】:

    • 我不确定这个,你能解释一下吗.. thx
    • 你创建了一个 observable 并且为了从 observable 获取响应应该使用订阅
    猜你喜欢
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 2021-07-05
    相关资源
    最近更新 更多