當(dāng)前位置:首頁(yè) > IT技術(shù) > Windows編程 > 正文

angular 同步調(diào)用api
2021-10-11 15:07:52

有時(shí)候會(huì)遇到這種情況,在a函數(shù)調(diào)用完之后再調(diào)用b函數(shù)接口,這時(shí)候就要用到angular http同步請(qǐng)求,下面是一種案例:

 //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會(huì)阻斷后面函數(shù)的執(zhí)行,直到當(dāng)前函數(shù)執(zhí)行完畢

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

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >