代码之家  ›  专栏  ›  技术社区  ›  Brother Eye

Angular 6-如何从网页和手机版本的网址下载文件?

  •  1
  • Brother Eye  · 技术社区  · 7 年前

    我正在做一个下载功能,可以在我的应用程序的网络版和手机版上使用Angular。以下是我当前的下载功能:

    export(status, id) {
        this.equipmentService.export(status, id).subscribe(data => {
            const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
            var link = document.createElement('a');
            link.href = window.URL.createObjectURL(blob);
            link.download = 'Export data equipment.xlsx';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });
    }
    

    <a> 标记而不是创建一个新的,但它也不起作用。

    有没有办法同时下载网页版和手机版?

    下面是激活函数的元素:

    <td mat-cell *matCellDef="let row">
        <button mat-icon-button [matMenuTriggerFor]="menu" (click)="$event.stopPropagation()">
            <mat-icon>more_vert</mat-icon>
        </button>
        <mat-menu #menu="matMenu" class="mat-menu">
            <button mat-menu-item (click)="editEquipment(row.Equipment_Id, $event, true)" *ngIf="isEditAvailable">
                <span>Edit</span>
            </button>
            <button mat-menu-item (click)="mark(1 , row.Equipment_Id)">
                <span>Mark Available</span>
            </button>
    
            <!-- Download button -->
            <button mat-menu-item (click)="export(2, row.Equipment_Id)" *ngIf="isViewDetailAvailable">
                <span>Export</span>
            </button>
            <!---->
    
            <button mat-menu-item (click)="deleteEquipment(row.Equipment_Id)" *ngIf="isEditAvailable">
                <span>Remove</span>
            </button>
        </mat-menu>
    </td>
    
    0 回复  |  直到 7 年前
    推荐文章