【发布时间】:2016-09-19 13:22:08
【问题描述】:
我正在使用 Angular 2 并在使用可观察的 Property '_body' does not exist on type 'Response' 时收到此错误。代码如下
this.securitiesService.getMarketMovers()
.subscribe(data => {
console.log(JSON.parse(data._body))
});
getMarketMovers 函数就是这样的:
getMarketMovers() {
return this._http.get('...url address...')
}
我尝试将data 设置为输入any,但这对我不起作用。该代码有效,并且数据上肯定有一个_body 属性,但它仍然会引发错误,我无法使用此错误进行构建。
非常感谢任何帮助。
【问题讨论】:
-
显示
getMarketMovers方法代码。 -
试试
data.json()._body -
您遇到运行时错误或编译时错误?对我来说听起来像是一个编译时错误,所以你必须将
data变量转换为正确的类型。或者你的getMarketMovers函数应该返回正确的类型! -
谢谢!我把
:any放在我的 getMarketMovers 函数getMarketMovers(): any之后,它可以工作
标签: angular typescript observable