在表格 Angular 8 中添加链接

问题描述 投票:0回答:2

我有一个包含一些列的表格,还有一个可以单击和下载的“文档”列。 我怎样才能只将文档名称设为链接?

HTML

<p-table #dt3 [columns]="colsPermessi" [value]="permessi" [paginator]="true" [scrollable]="false" [rows]="10" [autoLayout]="true">

<ng-template pTemplate="header" let-columns>
    <tr>
       <th *ngFor="let col of columns" pResizableColumn>{{col.header}} </th>
       <th>Azioni</th>
       <th>Permessi</th>
    </tr>
 </ng-template>

  <ng-template pTemplate="body" let-rowData let-columns="columns">
     <tr [pSelectableRow]="rowData">
         <td *ngFor="let col of colsPermessi">
            {{rowData[col.field]}}
         </td>
     </tr>
  </ng-template>

因此,我希望“文档”列可单击,单击时它会调用“downloadFile ()”函数。 我该怎么做?

angular html-table hyperlink download primeng
2个回答
2
投票

这可以使用 *ngIf 来分隔你的案例来完成。对于 documento 列,使用 ngIf 插入超链接标记。对于其他所有内容,只需插入文本即可。请参阅下面的示例:

  <ng-template pTemplate="body" let-rowData let-columns="columns">
     <tr [pSelectableRow]="rowData">
         <td *ngFor="let col of colsPermessi">
            <span *ngIf="col.header == 'Documento'><a [href]="col.url">{{rowData[col.field]}}</a></span>
            <span *ngIf="col.header != 'Documento'>{{rowData[col.field]}}</span>
         </td>
     </tr>
  </ng-template>

0
投票

我可以看到/a标记,但我看不到标记

© www.soinside.com 2019 - 2024. All rights reserved.