Hi Siva,
Your call to the method is sync, but the actual execution is async. Additionally, your method1 calls method2, which has what we call a side effect. (Setting that local path variable).
You can do several approaches here, e.g. use a promise, like Tito suggested:
buttonClick() {
method1()
.then(() => {
router.navigateByUrl(path);
});
Of course, you also need to make method1 a promise that doesn't return until method2 with it's side effect is executed:
method1() {
return apiCall()
.then(result => this.method2(result));
}
Alternatively you can make your buttonClick an async function, then it might be easier to understand, so now (together with method1 change above), your buttonClick looks like this:
async buttonClick() {
await method1();
return router.navigateByUrl(path);
}
There are other ways to do this, but this should get you started.
Zlatko