我们正在使用Angular 5,在我们的项目中,我们使用REST创建/修改UI中的值并存储在数据库中。
修改UI后,单击“保存”。用户界面不会显示修改后的用户界面,而不是之前的界面。在IE(ctrl + F5)中进行硬刷新时,它正在进行REST调用并显示正确的值。这只发生在IE 11和Chrome中,它运行正常。
请告诉我们是否可以从代码中控制仅清除此应用程序的缓存,或者赞赏任何其他建议。
谢谢vinod
要解决您的问题,您需要覆盖RequestOptions
并设置如下所示的'Cache-Control': 'no-cache',
定制请求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 }
]
})
希望这个帮助!