How to make FileReader work with Angular2?

后端 未结 5 1668
醉酒成梦
醉酒成梦 2020-12-06 01:32

How to make FileReader work with Angular2!!

When reading a file from client side with Angular2 and Typescript,

I try to us

5条回答
  •  攒了一身酷
    2020-12-06 01:49

    Just add

    fr.readAsText(event.files[0]);
    

    After the onLoad definition.

    Maybe this can help you, this is my upload handler function for the file upload library of primeng

    archivoUploadHandler(event) {
      let contenido;
      let fr = new FileReader();
      fr.onload = (e) => {
        contenido = fr.result;
        console.log(contenido);
      };
      fr.readAsText(event.files[0]);
    }
    

提交回复
热议问题