How to read csv file in Angular-4 assets

后端 未结 2 1218
北荒
北荒 2021-02-10 14:17

I am new to angular-4 and I want to read a csv file from angular-4 assets directory, file size 5mb and I dont\'t want to read this file from django back-end server because this

2条回答
  •  北海茫月
    2021-02-10 14:36

    In case you use the new HttpClient class (@angular/common/http), then you will have to set the responseType to 'text', otherwise the HttpClient class would try to interpret the content as json and raise a SyntaxError...

    e.g.:
    this.http.get('assets/file.csv', {responseType: 'text'})
        .subscribe(
            data => {
                console.log(data);
            },
            error => {
                console.log(error);
            }
        );
    

提交回复
热议问题