Promises - this.fileLoad..then is not a Function

Asked

Viewed 41 times

0

Good afternoon.

I’m having this error - this.fileLoad.then is not a Function, could someone please explain to me why this is happening?

fileLoad(){

    return new Promise((resolve, reject) =>{

        let fileReader = new FileReader();

        let fieldFile = [...this.formID].find(element =>{

            if(element.type === "file"){

                return element.files;

            }
        });

        fileReader.onload = () =>{

            fileReader.result;
            resolve(fileReader);
        }

        fileReader.onerror = () =>{

            reject("erro");

        }

        fileReader.readAsDataURL(fieldFile.files[0]);
    }

)};

this.fileLoad.then(    
        (content)=>{
            console.log(content);

        },
        (e)=>{

            console.log(e);

 })

Uncaught Typeerror: this.fileLoad.then is not a Function at userController.adduser (userController.js:76) at userController.loadFiles (userController.js:57) At Htmldocument.document.addeventlistener.Event (userController.js:20)

  • Have you tried without the this?

  • Thanks found the error, forgot to set the call to a Function this.fileLoad.then - this.fileLoad.then();

  • 1

    Bruno, if you can, mark the question as answered friend.

1 answer

1


You need to call the function with parentheses, this.fileLoad(). then(...

  • No need no man.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.