Angular Service Worker SwUpdate.available not triggered

前端 未结 6 2355
旧巷少年郎
旧巷少年郎 2020-12-13 18:51

I\'m having a hard time integrating angulars service worker into my application. I followed the guide and it works so far. I can create a shortcut on my homescreen and launc

6条回答
  •  情歌与酒
    2020-12-13 19:07

    To check if newer a version of Angular is available, you can call below method from any component, or just copy the IsNewerVersionAvailable method in app.component.

    export class DataService {
        
        constructor(private http: HttpClient, private swUpdate: SwUpdate) { }
    
        private available: boolean = false;
     
        IsNewerVersionAvailable() {
            if (this.swUpdate.isEnabled) {
                this.swUpdate.available.subscribe(() => {
                    this.available = true;
                });
                console.log(this.available);
            }
            return this.available;
        }    
    }
    

提交回复
热议问题