angular2 services - How to download data from JSON file in angular 2 -
this component file response coming service file. want download file json records in it. code able download file in file not getting json data. displaying [object object].
export class mydrivecomponent implements oninit { drivelists: any; data: any; constructor(private downloaddataservice : downloaddataservice) { } ngoninit(){ downloadfile(){ console.log(this.data); this.downloaddataservice.downloadfile(). subscribe(data => {this.data = json.stringify(data)}, err => console.log(err), () => this.download(this.data)); } download(data) { console.log(data); var blob = new blob([data], { type: 'text/csv' }); var url= window.url.createobjecturl(blob); window.open(url); } } this service file
export class downloaddataservice { constructor(private http: http){ } result : any; downloadfile() { return this.http.get('assets/json/download.json').map(response => response.json().downloaddata); } }
Comments
Post a Comment