首页 > 解决方案 > 在 IE 11 Angular 5 缓存问题中

问题描述

我们正在使用 Angular 5,在我们的项目中,我们正在创建/修改 UI 中的值并使用 REST 存储在数据库中。

修改 UI 并单击“保存”后。UI 未显示修改后的 UI 而不是前一个。当在 IE (ctrl + F5) 中执行硬刷新时,它会进行 REST 调用并显示正确的值。这仅在 IE 11 中发生,在 Chrome 中运行良好。

请让我知道我们是否可以从代码中控制仅清除此应用程序的缓存,或者任何其他建议表示赞赏。

谢谢葡萄酒

标签: angularinternet-explorercachingbrowser-cache

解决方案


要解决您的问题,您需要覆盖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 }
    ]
})

希望这个帮助!


推荐阅读