我真的不知道如何问这个问题或发生了什么事。
我正在执行API调用以获取数据,例如:
Exception in thread "main" java.lang.IllegalStateException
at com.google.common.base.Preconditions.checkState(Preconditions.java:495)
at com.google.api.client.util.Preconditions.checkState(Preconditions.java:79)
at com.google.api.client.googleapis.batch.BatchRequest.execute(BatchRequest.java:215)
at com.google.cloud.storage.spi.v1.HttpStorageRpc$DefaultRpcBatch.submit(HttpStorageRpc.java:199)
我所有的API调用看起来都是这样。现在,当将数据主体记录到组件中时,我得到了一个非常奇怪的响应:
所以看来我的数组中有2个对象,但是扩展数组时……没有数据。
在浏览器的“网络”选项卡上查看时,阵列中实际上有数据。所以我不知道发生了什么。这会导致以下错误:
getSingleGroupStats(uuid:string, req:any){
return this.http.get(`${this.resourceUrl}/${uuid}/endpoint`, {
params: req,
observe: 'response',
})
}
因为该组件看不到数据。
我不知道该怎么办或正在发生什么。
编辑
我实际上正在订阅组件内部的响应,例如:
cannot read property whatever of undefined
这个this.service.getSingleGroupStats('1234', {}).subscribe(
(res:HttpResponse<any>) => {
console.log('single stats -> ', res.body)
}
)
就是所有数据都不可靠的地方。
答案 0 :(得分:3)
由于您正在观察“响应”,因此将获得带有标题和正文的整个响应。它返回类型为HttpResponse的Observable,而不仅仅是JSON数据。如文档所述,您只需执行response.body即可访问数据。