当前位置:首页 > IT技术 > Windows编程 > 正文

angular 同步调用api
2021-10-11 15:07:52

有时候会遇到这种情况,在a函数调用完之后再调用b函数接口,这时候就要用到angular http同步请求,下面是一种案例:

 //getDetails
  public async getLocationDetails(): Promise<any>{
    
    let customBody =  {
      "appID"       :  APP_CONFIG['appID'],
      "apiVersion"  : 2,
      "eventID"     : atob(sessionStorage.getItem('lyc_event_id')),
    }

    const locationDetailsRes=await this.httpService.callEMP(environment.API.getEventInfo,customBody).toPromise()
    if(locationDetailsRes["status"] == '0'){
      /**
       * 0 is mean success. other status value is mean error
       **/
      sessionStorage.setItem('currentLocationName',locationDetailsRes['event']['eventName'])
    }else{
      this.snackBar.open(this.translateService.instant('General.Error.something_went_wrong_text'), '×', { panelClass: 'error', verticalPosition: 'top', duration: 5000 });
    }
  }
  public async onLoginFormSubmit() {
    await this.getLocationDetails();
}    

await会阻断后面函数的执行,直到当前函数执行完毕

本文摘自 :https://www.cnblogs.com/

开通会员,享受整站包年服务立即开通 >