1

I'm trying to pass a callback as a function parameter.

For example:

public abc1(doc:any){        
        console.log('abc1');    
    }

    public abc2(model:any){
        console.log('abcd2');    
    }

 xyz.load(id.replace('/', ''), abc1, abc2);

Here abc1 and abc2 my callback functions and I'm trying to pass these functions in xyz.load as 2 and 3 arg. All are in the same component.

1 Answer 1

3

You could define the load method like so:

load(id: string, callback1: (doc: any) => void, callback2: (model: any) => void) {
    // do your stuff here
    callback1(theDocument);
    callback2(theModel);
}

And call it like this:

xyz.load(id.replace('/', ''), abc1, abc2);
Sign up to request clarification or add additional context in comments.

2 Comments

what are callback1(theDocument); callback2(theModel); here?
abc1 and abc2 in your case. theDocument and theModel are just placeholders since I don't know where those are coming from.

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.