响应即将到来,但请求 api 调用未在具有 angular9 的网络面板中触发

问题描述

通过 promise 或 observable 生成的请求 api 有时会收到响应,但请求 api 调用未在 chrome 网络面板中触发。响应也出错 例子: this.getTimeCollections().then(data=>{console.log(data)});

//在 service.ts 中

getTimeCollections():Promise{

    const url = `${this.publicUrl}/time_collections`;

    return this.httpClient.get(url).toPromise();

}

这里第一次返回正确的响应数据,但如果我们再次调用相同的函数,它返回我们检查控制台打印的数据,但请求未显示网络面板,响应也未更新,它返回以前的数据。 这里我在这个模板中使用了 matTabmodule,如果我们删除 matTab 选择器,那么它工作正常。

解决方法

您需要订阅 http observable 才能执行:

const url = `${this.publicUrl}/time_collections`;
const response$ = this.httpClient.get(url);
response$.subscribe(response=>console.log(response));

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...