【问题标题】:In IE 11 Angular 5 Cache Issue在 IE 11 Angular 5 缓存问题中
【发布时间】:2019-07-13 19:07:21
【问题描述】:
我们正在使用 Angular 5,在我们的项目中,我们正在创建/修改 UI 中的值并使用 REST 存储在数据库中。
修改 UI 并单击“保存”后。 UI 未显示修改后的 UI 而不是前一个。当在 IE (ctrl + F5) 中执行硬刷新时,它会进行 REST 调用并显示正确的值。这仅在 IE 11 中发生,在 Chrome 中运行良好。
请让我知道我们是否可以从代码中控制仅清除此应用程序的缓存或任何其他建议。
谢谢
葡萄酒
【问题讨论】:
标签:
angular
internet-explorer
caching
browser-cache
【解决方案1】:
要解决您的问题,您需要覆盖RequestOptions 并设置'Cache-Control': 'no-cache',,如下所示
custom-request-option.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'
});
}
you.app.module.ts
@NgModule({
...
providers: [
...
{ provide: RequestOptions, useClass: CustomRequestOptions }
]
})
希望得到帮助!