angular - 在 IE 11 Angular 5 缓存问题中
问题描述
我们正在使用 Angular 5,在我们的项目中,我们正在创建/修改 UI 中的值并使用 REST 存储在数据库中。
修改 UI 并单击“保存”后。UI 未显示修改后的 UI 而不是前一个。当在 IE (ctrl + F5) 中执行硬刷新时,它会进行 REST 调用并显示正确的值。这仅在 IE 11 中发生,在 Chrome 中运行良好。
请让我知道我们是否可以从代码中控制仅清除此应用程序的缓存,或者任何其他建议表示赞赏。
谢谢葡萄酒
解决方案
要解决您的问题,您需要覆盖RequestOptions
并设置'Cache-Control': 'no-cache',
如下
自定义请求选项.ts
import { Injectable } from '@angular/core';
import { BaseRequestOptions, Headers } from '@angular/http';
@Injectable()
export class CustomRequestOptions extends BaseRequestOptions {
headers = new Headers({
'Cache-Control': 'no-cache',
'Pragma': 'no-cache',
'Expires': 'Sat, 01 Jan 2000 00:00:00 GMT'
});
}
你.app.module.ts
@NgModule({
...
providers: [
...
{ provide: RequestOptions, useClass: CustomRequestOptions }
]
})
希望这个帮助!
推荐阅读
- java - Firestore 的 CompletableFuture
- python - 如何将循环在不同数据库上的 MySQL 查询组合到一个 excel 文件中(附加结果数据框)
- python - 从 Geopy 库中获取纬度和经度时出错
- android - findautocompletepredictionsrequest 是收费的吗?
- flowtype - 允许函数接受数组或元组,但强制数组文字在 Flow 中被视为元组
- java - 将 Java int 转换为 C 无符号 int
- django - 如何在没有 try 语句的情况下检测未处理的异常
- c# - Visual Studio Edit-GoToAll (CTRL+Comma) 包含引用程序集
- python-3.7 - 启动后的自定义调度程序线程由 gunicorn 的主线程和工作线程并行运行
- node.js - 参考错误:未定义文本编码器