Last active
November 7, 2017 16:25
-
-
Save lacolaco/1cc4cc9b17b9d0e5cc7497b1a0772b51 to your computer and use it in GitHub Desktop.
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 { Component } from '@angular/core'; | |
// Import SwUpdate from NGSW | |
import { SwUpdate } from '@angular/service-worker'; | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
... | |
`, | |
styles: [] | |
}) | |
export class AppComponent { | |
title = 'app'; | |
// Inject SwUpdate | |
constructor(private swUpdate: SwUpdate) { | |
// Subscribe new worker is available | |
this.swUpdate.available.subscribe(() => { | |
if(window.confirm('新しいバージョンに更新しますか?')) { | |
window.location.reload(true); | |
} | |
}); | |
// Check for new version | |
this.swUpdate.checkForUpdate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment