angular - 使用 Angular 10 部署后为客户端自动重新加载

标签 angular angular10

目前,我的应用程序已部署,所有 js 都有时间戳版本。现在,当我再次构建我的 angular 应用程序时,js 将有一个新的时间戳版本。
enter image description here
有没有一种方法可以比较我的构建版本,如果不匹配,则允许用户从应用程序注销?

最佳答案

使用“@angular/service-worker”包的“SwUpdate”,您可以检查应用程序的当前版本和可用版本,并可以通过检查版本来执行您想要执行的操作。
例子:

import { SwUpdate } from '@angular/service-worker';

constructor(private swUpdate: SwUpdate) {}

//Here you can check the versions
this.swUpdate.available.subscribe((event) => {
   console.log('current version: ', event.current);
   console.log('available version: ', event.available);
   if (confirm('Software update avaialble.')) {
       this.swUpdate.activateUpdate().then(() => {
          //Perform your action here
          window.location.reload()
       });
   }
});

关于angular - 使用 Angular 10 部署后为客户端自动重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65576630/

相关文章:

angular - 在 RXJS Tap 操作符内部时,Console.Log 不会执行

angular - NPM 安装的应用程序(例如文件 C :\Users\name\AppData\Roaming\npm\ng. ps1)无法加载,因为在此系统上禁用了运行脚本

angular - 在 kendo-daterange 上设置日期范围限制

angular - Angular 7 中名称错误的表单控件没有值访问器

angular - 在 Angular 组件中设置 ngx-lightbox 时遇到问题

angular - ngIf 异步管道作为仅空检查的值

angular - 来自 ngFor 项目的动态 routerLink 值给出错误 "Got interpolation ({{}}) where expression was expected"

angular - 在 NgModule 中使用实例化依赖

angular - 为什么 ngOnChanges 需要时间。是异步的吗?

Angular:使用 Typescript 使表单值只读变灰并使数据获取有效