AngularSwUpdate已被弃用
创始人
2024-10-29 17:00:48
0

使用新的更新API来代替SwUpdate。

示例代码:

import { NgModule } from '@angular/core';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';

@NgModule({
  imports: [ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })],
})
export class AppModule {}

在该示例中,我们使用了 ServiceWorkerModule 来代替旧的 SwUpdate 。通过在应用程序的根模块中导入 ServiceWorkerModule 并使用 register() 方法,我们可以注册并启用ServiceWorker。

此外,还可以使用 updateActivated 事件来获取更新已激活的信息,示例如下:

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

@Component({
  selector: 'app-root',
  template: `

Angular PWA Example

`, }) export class AppComponent { constructor(private swUpdate: SwUpdate) { swUpdate.available.subscribe((event) => { console.log('A new version is available'); swUpdate.activateUpdate().then(() => document.location.reload()); }); swUpdate.activated.subscribe((event) => { console.log('The new version has been activated'); }); } }

在上面的示例代码中,我们使用 available 事件来订阅当前可用的更新信息,并使用 activated 事件来获取已激活的更新信息。通过使用 SwUpdate 的这些方法,我们可以轻松地更新我们的PWA应用程序。

相关内容

热门资讯

今日科普!微信卡五星辅助器,微... 今日科普!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)攻略;1.微信卡五星辅助器 选牌创建...
重大通报!微乐自建房辅助工具挂... 重大通报!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)app1、打开软件启动之后找到中间...
让我来分享经验!微乐自建房辅助... 让我来分享经验!微乐自建房辅助工具免费app,微乐自建房脚本免费入口(开挂自建房)脚本1、微乐自建房...
记者揭秘!微乐小程序自建房辅助... 记者揭秘!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)软件微乐小程序自建房辅助...
必看攻略!微乐自建房辅助工具免... 必看攻略!微乐自建房辅助工具免费app,微乐家乡麻将自建房辅助app(开挂自建房)攻略1、每一步都需...
必备攻略!微乐家乡麻将自建房辅... 必备攻略!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)技巧1、必备攻略!...
查到实测辅助!微信卡五星辅助器... 查到实测辅助!微信卡五星辅助器,微乐家乡麻将自建房辅助app(开挂自建房)教程1、超多福利:超高返利...
传递经验!微乐自建房辅助工具挂... 传递经验!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)技巧1、操作简单,无需微乐自建房辅...
一分钟教你!微信卡五星辅助器,... 一分钟教你!微信卡五星辅助器,微乐家乡麻将自建房辅助app(开挂自建房)插件1、这是跨平台的微乐家乡...
传递经验!微乐小程序自建房辅助... 传递经验!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)脚本传递经验!微乐小程序...