【发布时间】:2021-05-12 12:14:55
【问题描述】:
我是 Typescript 的新手,我想将 HTTP GET 的响应保存到由接口定义的类型的数组中。
getErrors() {
return this.http.get<ErrorsInterface[]>(environment.apiUrl+'errors').toPromise()
}
然后我这样声明数组并调用函数getErrors()
errorsData: ErrorsInterface[]= []
this.errorsData = await this.ErrorsService.getErrors()
this.errorsData.forEach(res => {
console.log(res.number)
})
但我收到以下错误:
错误错误:未捕获(承诺中):TypeError:this.errorsData.forEach 不是函数 TypeError: this.errorsData.forEach 不是函数
感谢您的帮助
【问题讨论】:
标签: angular typescript interface