Search code examples
angularangular2-httpangular2-jwt

Send http request before sending other http requests angular 2


I need to get jwt token via http module then make other requests with this token in header. How I can make delay of app initialization till token get request resolved?


Solution

  • this.http.get(...)
    .map(response => response.json())
    .flatMap(response => this.http.get(...).map(response => response.json())
    .subscribe(response => this.result = response);
    

    You can use How to pass parameters rendered from backend to angular2 bootstrap method to delay app-initialization.