【问题标题】:Angular SwUpdate activated depricationAngular SwUpdate 激活贬值
【发布时间】:2022-01-12 16:03:35
【问题描述】:

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

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

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

我应该怎么做才能解决这个警告?

【问题讨论】:

    标签: angular deprecated angular-service-worker


    【解决方案1】:

    你必须把activated改为activateUpdate(),并把它当作Promise

    this.swUpdate.activateUpdate().then(() => {
     ...
    });
    

    【讨论】:

      【解决方案2】:

      我相信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,
        })));
      

      【讨论】:

        猜你喜欢
        • 2021-09-07
        • 1970-01-01
        • 2017-10-30
        • 1970-01-01
        • 2018-01-22
        • 2018-06-09
        • 2023-02-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多