亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

angular返回數據綁定本地變量

angular返回數據綁定本地變量

墨色風雨 2019-02-05 16:26:45
[setting.component.ts]  TagList = [];  public getTagList() {    this.settingService.getTags()       .subscribe((response) => {        this.TagList = response.data;         console.log(this.TagList);  //A     });     console.log(this.TagList);  //B   }setting.service.tspublic getTags(): Observable<any> {     return this.http.get<any>(`${this.appConfig.apiUrl}/setting/setting/`, { withCredentials: true }); }如圖所示,A處可以正常打印后臺返回的數據但是B處是undefined,有朋友說是異步的原因,B處用setTimeout同樣是undefined,小白求大佬們指導,感謝
查看完整描述

1 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

好吧,確實是異步的,但不清楚為什么用setTimeout(console.log(this.TagList))仍然不行。不過不必糾結這個問題,去html里放心用TagList就是了。

查看完整回答
反對 回復 2019-02-05
  • 1 回答
  • 0 關注
  • 587 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號