Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度服务人员-立即检查更新_Angular_Service Worker - Fatal编程技术网

Angular 角度服务人员-立即检查更新

Angular 角度服务人员-立即检查更新,angular,service-worker,Angular,Service Worker,我在Angular项目中设置了一个服务人员,其中一部分我们设置了服务人员,以便在Angular项目发生更改时检查更新。问题是,如果有更新,当应用程序加载时,服务工作大约需要2-3分钟才能检测到更新。我们如何更改此设置,使其在加载应用程序时立即检查更新 目前我们的代码如下。我们有一个名为update.service的服务,它有一个构造函数来检查服务工作者是否已启用,并具有初始化检查更新的功能 constructor(private updates: SwUpdate) { con

我在Angular项目中设置了一个服务人员,其中一部分我们设置了服务人员,以便在Angular项目发生更改时检查更新。问题是,如果有更新,当应用程序加载时,服务工作大约需要2-3分钟才能检测到更新。我们如何更改此设置,使其在加载应用程序时立即检查更新

目前我们的代码如下。我们有一个名为update.service的服务,它有一个构造函数来检查服务工作者是否已启用,并具有初始化检查更新的功能

constructor(private updates: SwUpdate) {     
    console.log('UpdateService','constructor()','Check Service Worker Active',null);
    if (!this.updates.isEnabled) {
      console.log('UpdateService','constructor()','Service Worker Disabled',null);
    } else {
      console.log('UpdateService','constructor()','Service Worker Enabled',null);
    }
           
  }
  /*
  ** name: Init Check Update
  ** desc: Update check on init app - DOESN"T WORK
  */
  initCheckForUpdate(): void {
    // check update on init in prod mode only
    if (this.updates.isEnabled) {
      this.updates.available.subscribe(event => {
        //console.log('Event', event);
        console.log('Current version is', event.current);
        console.log('Available version is', event.available);  
        this.updates.activateUpdate().then(() => {
          alert('There is a new version of the app. Press OK to autoupdate.');
          document.location.reload();
        });
      });
    }
  }
然后在加载的第一个页面中,我们在ngOnInit()中

感谢您的帮助似乎有很多人在各种论坛上提出了这个问题,但我还没有找到答案

this.updateService.initCheckForUpdate();