Created
March 14, 2022 11:08
-
-
Save Mustafa-Omran/914c545fd83369b3d04a9fb1d8fd67d3 to your computer and use it in GitHub Desktop.
Angular - Service Worker (Dealing With Updates)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { MatSnackBar } from '@angular/material/snack-bar'; | |
import { SwUpdate } from '@angular/service-worker'; | |
@Injectable() | |
export class UpdateService { | |
constructor(private swUpdate: SwUpdate, | |
private snackbar: MatSnackBar) { | |
this.swUpdate.available.subscribe(event => { | |
const snack = this.snackbar.open('Update Available', 'Reload', { duration: 5000}); | |
snack.onAction().subscribe(() => { | |
window.location.reload(); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment