[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 回答

慕工程0101907
TA貢獻1887條經驗 獲得超5個贊
好吧,確實是異步的,但不清楚為什么用setTimeout(console.log(this.TagList))仍然不行。不過不必糾結這個問題,去html里放心用TagList就是了。
- 1 回答
- 0 關注
- 608 瀏覽
添加回答
舉報
0/150
提交
取消