File

src/lib/services/download.service.ts

Index

Methods

Methods

download
download(text: string, filename: string)
Parameters :
Name Type Optional
text string No
filename string No
Returns : void
import { Injectable } from "@angular/core";

@Injectable()
export class DownloadService {

    download(text: string, filename: string) {
        const element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);

        element.style.display = 'none';
        document.body.appendChild(element);

        element.click();

        document.body.removeChild(element);
    }
}

result-matching ""

    No results matching ""