【问题标题】:How to insert hyperlinks inside an accordion?如何在手风琴内插入超链接?
【发布时间】:2019-01-25 22:49:10
【问题描述】:

我需要在手风琴内插入一堆蓝色超链接。所以当我们点击标题时,出现的展开区域会包含几行调用某个函数的代码。

我尝试按照 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>

【问题讨论】:

    标签: html hyperlink angular-material material-design accordion


    【解决方案1】:

    首先,删除mat-form-field,如果您只想在手风琴中添加一个简单的链接,则不需要(这实际上是破坏您的代码的原因)。

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

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

    如果你想改用label,可以这样使用:

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

    它应该有一个值,否则它是不可见的,你不能点击它。

    Here 是一个堆栈闪电战,您的示例代码已被编辑以使其工作。

    【讨论】:

    • 哇。你让它看起来超级简单。非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 2011-02-04
    • 2013-02-06
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多