如何在手风琴中插入超链接?

How to insert hyperlinks inside an accordion?

我需要在手风琴中插入一堆蓝色超链接。所以当我们点击标题时,出现的扩展区域将包含几行调用一些函数。

我尝试按照 Angular Material 网站上的示例进行操作: https://stackblitz.com/angular/ybovddobxlj?file=app%2Fexpansion-overview-example.html

我已将 expansion-overview-example.html 修改为以下内容:

<mat-accordion>
  <mat-expansion-panel>
    <mat-expansion-panel-header>
        <mat-panel-title>
            ALL FILES
        </mat-panel-title>
    </mat-expansion-panel-header>

    <div> <!-- To put them on separate lines -->
        <mat-form-field>
            <label title="File 1" onclick="openFile1()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
        </mat-form-field>
    </div>

    <div> <!-- To put them on separate lines -->
      <mat-form-field>
            <label title="File 2" onclick="openFile2()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
      </mat-form-field>
    </div>

  </mat-expansion-panel>
</mat-accordion>

首先,删除 mat-form-field,如果您只想在手风琴中使用简单的 link,则不需要这样做(这实际上会破坏您的代码)。

只需添加一个带有 (click) 事件处理程序的简单 p 标记(它不是 Angular 中的 onclick)。这应该可以解决问题:

<div>
  <p (click)="openFile1()">File 1</p>
</div>

如果你想使用label,像这样使用它:

<div>
  <label (click)="openFile2()">File 2</label> 
</div>

应该有值,否则不可见,不能点击

Here is a stackblitz with your sample code edited to make it work.