我正在创建一个应用程序来浏览和下载电话录音。如何用Angular 2触发文件下载?
此应用程序的一部分是一个用* ngFor填充以显示录制内容和相关信息的表格。表格中的每一行还有一个复选框,用于标记要下载的记录。我已经到了可以将console.log链接指向我正在使用的测试mp3的地步,但我无法弄清楚如何实际触发所述mp3的下载。
我真的很希望能够使用Typescript和不使用jQuery来做到这一点。
<table>
<thead>
<tr>
<th>
<input type="checkbox" [checked]="isAllChecked()" (change)="checkAll($event)"> </th>
<th>Date</th>
<th>Time</th>
<th>Duration</th>
<th>Calling Number</th>
<th>Called Number</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr *ngFor="let entry of recordingsList">
<td>
<input type="checkbox" [(ngModel)]="entry.isSelected"> </td>
<td>{{entry.date}}</td>
<td>{{entry.time}}</td>
<td>{{entry.duration}}</td>
<td>{{entry.callingNumber}}</td>
<td>{{entry.calledNumber}}</td>
<td>
<button (click)="openPlayer(entry)" class="play-button"><i class="material-icons">play_arrow</i></button>
</td>
</tr>
</tbody>
</table>
-
// Download selected recordings
downloadSelected() {
let isSelected = this.recordingsList.filter(x => x.isSelected);
isSelected.forEach(x => console.log(x.audio));
}
-
任何援助不胜感激。
[Anchor element](https: //developer.mozilla.org/en/docs/Web/HTML/Element/a)有一个'download'属性。 –
@PavelStaselun我知道标签的下载属性。但我不明白如何将它应用于我的用例。 –