Skip to content

Instantly share code, notes, and snippets.

@lacolaco
Last active November 7, 2017 16:25
Show Gist options
  • Save lacolaco/1cc4cc9b17b9d0e5cc7497b1a0772b51 to your computer and use it in GitHub Desktop.
Save lacolaco/1cc4cc9b17b9d0e5cc7497b1a0772b51 to your computer and use it in GitHub Desktop.
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