Try the following
npm install file-saver --save
Then add a declarations file to your project like 'declarations.d.ts' and in it put
declare module 'file-saver';
In your systemjs.config.js, add the following to the map section
'file-saver': 'npm:file-saver/FileSaver.js'
And then import the library in your component or service like below
import { Component } from '@angular/core';
import * as saveAs from 'file-saver';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>
<button (click)="SaveDemo()">Save File</button>`,
})
export class AppComponent {
name = 'Angular';
SaveDemo() {
let file = new Blob(['hello world'], { type: 'text/csv;charset=utf-8' });
saveAs(file, 'helloworld.csv')
}
}
Hope it helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…