ionic/angular FileReader error (addEventListener is not a function) occurs in ios simulator

I have the function below and it works fine with ionic serve, but i get "reader.addEventListener is not a function" when I'm trying to run the same code on ios simulator. Could you help me, please, find out what is wrong?

createImageFromBlob(image: Blob) {
    let reader = new FileReader();
    reader.addEventListener(
      "load",
      () => {
        this.imageToShow = reader.result;
      },
      false
    );
    if (image) {
      reader.readAsDataURL(image);
    };
  };

Upvotes: 6

Views: 1818

Answers (1)

leonardofmed
leonardofmed

Reputation: 835

As stated here, the reader is not an element, so you should use onload in this case. This is an updated version, using the same method.

createImageFromBlob(image: Blob) {
  let reader = new FileReader();
  reader.onload = function () {
    this.imageToShow = reader.result;
  }
  if (image) {
    reader.readAsDataURL(image);
  }
}

Upvotes: 3

Related Questions