Several non-angular dependent requests

1

Hello, I'm doing an angular process, in the 'ngOnInit ()' method, where I need to perform 3 HTTP methods, which are asynchronous. one depends on the other's response. for example:

1st call: get a token

2nd call: it will only happen after the 1st, and will get the longitude and latitude

3rd call: will receive a list of objects, passing as parameters the token and the coordinates.

However, I do not know how to perform these methods in order, that is, wait for the response from one to start the other ...

First call code:

ngOnInit(): void { 
    this.apiDeSegurancaService.ObterToken().subscribe(
        res => { 
            this.apiDeSegurancaService.AdicionandoToken(res.access_token); 
        }, 
        error => { 
            console.log(error._body); 
            this.token = this.apiDeSegurancaService.ObtendoToken();
        }
    );
}

Thank you in advance ....

    
asked by anonymous 12.06.2018 / 16:07

1 answer

0

It is possible to perform this process using the switchmap, in the first calls and in the last use Subscrible ();

Ex:

CallPap1 (). switchmap (res => CallAPI2 ()). subscrible ();

    
10.08.2018 / 01:36