[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 });
}
as shown in the figure, the data returned by background can be printed normally at A
but B is undefined, some friends say it is asynchronous, and B uses setTimeout as well as undefined. Thank you