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
On Saturday, July 13, 2019 at 6:57:55 AM UTC+2, Sivaprakash Gopal wrote:
>
> Hi All,
>
> I am new angular, how to make method processing as sequential. Based on
> api response, i need to navigate to different component.
> In this case, how to make process sequential.
>
>
> let responseObj = null;
> let path = null;
> buttonClick(){
> method1();
> router.navigateByURL(path);
> }
>
>
> method1(){
> responseObj = api call();
> method2(responseObj);
> }
>
> method2(responseObj){
> path = processing - > responObj;
> }
>
> Thanks,
> Siva
>
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/dbec1b0a-1a3b-4062-9f74-e969519a1c80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.