[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.ts
public getTags(): Observable<any> { return this.http.get<any>(`${this.appConfig.apiUrl}/setting/setting/`, { withCredentials: true }); }
如图所示,A处可以正常打印后台返回的数据
但是B处是undefined,有朋友说是异步的原因,B处用setTimeout同样是undefined,小白求大佬们指导,感谢
慕工程0101907
相关分类