0

In my angular application i have to return the resolve form a the function callback.

Sample code:

new testPromise=new Promise((resolve,reject)=>{
   abc("test",successCallback,errorCallback)    
});

How can i call the resolve/reject from the callback functions

such as:

successCallback(data){
  resolve(data);

}
errorCallback(error){
  reject(error);
}

Is this possible or will i have to call the resolve/reject from inside the promise only?

1 Answer 1

2

Just pass them directly as the callback arguments:

let testPromise = new Promise((resolve, reject) => {
    abc("test", resolve, reject);
});

Do not create separate functions such as function successCallback(data) { resolve(data); } inside the promise constructor.

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.