Angular SwUpdate 激活 deprication

标签 angular typescript rxjs deprecated angular-service-worker

在我的 Angular 项目中,我有这种代码:

this.swUpdate.available.subscribe(() => {
  ...
});

它工作正常,但给了我关于 activated 被弃用的警告。

我应该怎么做才能修复此警告?

最佳答案

我相信 activatedactivateUpdate() 是不同的东西。您调用 activateUpdate(),然后当它完成时,activated 发生。

此外,activatedavailable 绝对是不同的东西(你的问题都提到了)。 available 表示检测到更新; activated 表示已经安装。

根据文档(https://angular.io/api/service-worker/SwUpdate),available 的替换是:

import {filter, map} from 'rxjs/operators';
// ...
const updatesAvailable = swUpdate.versionUpdates.pipe(
  filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
  map(evt => ({
    type: 'UPDATE_AVAILABLE',
    current: evt.currentVersion,
    available: evt.latestVersion,
  })));

关于Angular SwUpdate 激活 deprication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70684682/

相关文章:

angular - 如何在 Angular 7 中等待直到 DOM 准备就绪?

angular - 使用 LocalStorage 中的 AuthToken 为 NgRx Store 补水的正确方法和位置

typescript - 使用 typescript 扩展 JQueryStatic

typescript - 如何使用基于泛型类型的条件类型来描述约束?

Angular rxjs Observable.interval() 无法在 Chrome 中的后台选项卡上正确触发

javascript - typescript ,使用没有构造函数的类

angular - 我如何对子组件进行 Angular 路由

javascript - 解析JS SDK : Cannot use the Master Key, 未提供

javascript - 在生产代码中使用 setTimeout 安全吗?

Angular 2路由引发404错误