6

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);
    };
  };
3

1 Answer 1

3

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);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.