等到api响应到来,角度7

时间:2019-05-03 16:48:52

标签: typescript promise angular7

正在调用其他API,而不是等待注销api响应。

当我单击注销时(会调用api),但仪表板api也会在重定向到注销页面之前立即被调用。

Component.ts

this.loginService.logoutApi().subscribe((data) =>{

    this.storage.set(STORAGE_LOGIN_RES,'');

    this.router.navigate(['/login'])
    console.log(this.storage.get(STORAGE_LOGIN_RES));
},
   (error: any) => {
    this.isError = "Contact your administrator.";
}
);

Service.ts

try {
    let url = WebUrls.logoutApi;

    let user_details =  this.getSession();
        let headers = new HttpHeaders({
        'Content-Type': 'application/json',
        'Authorization': user_details
        });
    let options = { headers: headers,observe: 'response' };

    return this.http.get(url,{
          headers: headers,
          observe: 'response'
        })
} catch (e) { console.log(e) }

0 个答案:

没有答案