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应用程序。

相关内容

热门资讯

突发!wepoker辅助器最新... 突发!wepoker辅助器最新版本更新内容,微信微乐自建房辅助工具,揭幕透视(详细教程)-哔哩哔哩1...
透视总结!hhpoker视频巡... 透视总结!hhpoker视频巡查真的假的,hh poker辅助器先试用(透视)确实有神器(哔哩哔哩)...
今年以来!epoker免费透视... 今年以来!epoker免费透视脚本,微乐小程序脚本入口,开挂脚本(揭秘有挂)-哔哩哔哩1、epoke...
透视解迷!hhpoker辅助器... 透视解迷!hhpoker辅助器,hhpoker透视脚本(透视)确实存在有神器(哔哩哔哩)1、让任何用...
为了进一步!pokerrrr2... 您好,pokerrrr2辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
脚本辅助!aapoker免费透... 脚本辅助!aapoker免费透视脚本,aapoker怎么设置抽水(透视)都是真的是有方法(哔哩哔哩)...
此事迅速冲上热搜!hh pok... 此事迅速冲上热搜!hh poker软件,微信微乐辅助器免费安装,解谜透视(新版有挂)-哔哩哔哩1、h...
脚本专业!德普之星透视辅助软件... 脚本专业!德普之星透视辅助软件,德普之星的辅助工具介绍(透视)总是有方法(哔哩哔哩)1、实时透视辅助...
透视私人局!菠萝辅助器免费版的... 透视私人局!菠萝辅助器免费版的特点,微乐小程序辅助开挂,总结脚本(有挂规律)-哔哩哔哩1、下载好菠萝...
透视有挂!pokermaste... 透视有挂!pokermaster脚本,贵州微乐自建房辅助软件下载,推荐透视(竟然有挂)-哔哩哔哩1、...