【发布时间】:2021-01-01 18:28:10
【问题描述】:
我的数据库中有数据,并且我已经实现了后端 API 服务。我正在尝试在前端显示数据并进行渲染,但我不确定它为什么不显示。 任何建议或帮助将不胜感激。
我的后端 Get 方法之一
@Controller('helpSection')
export class HelpSectionController {
constructor(private readonly helpSectionService: HelpSectionService) {}
@Get()
getHelpSection():Promise<HelpSectionEntity[]>{
return this.helpSectionService.getHelpSection();
}
我的前端 HTTP 获取之一
constructor(private http: HttpClient) { }
getHelpSection() {
return this.http.get<HelpSection[]>(`${environment.api.chart}/helpSection`).pipe(first());
}
只是为了测试,我在我的组件中这样做了
TS
import {HelpService} from '../../core/services/help.service'
constructor(private HelpService: HelpService) {}
helpSection$ = this.HelpService.getHelpSection();
ngOnInit(): void {
this.HelpService.getHelpSection().subscribe(() => {
} )
}
HTML
{{helpSection$ | async}} // this display just [object Object]
<div *ngFor= "let help in helpSection$ | async">{{help.sectionName}}</div> // This is not showing anything
【问题讨论】:
-
这说明你的前端绑定错误。您会看到 json 键值对的 object, object。绑定应该拼出键名。
标签: angular typescript api backend nestjs