Skip to content

Instantly share code, notes, and snippets.

@ngohungphuc
Created November 29, 2018 16:18
Show Gist options
  • Save ngohungphuc/ab8cafbaadc37b1eb8fc6270d7adb94e to your computer and use it in GitHub Desktop.
Save ngohungphuc/ab8cafbaadc37b1eb8fc6270d7adb94e to your computer and use it in GitHub Desktop.
import { Component, OnInit } from "@angular/core";
@Component({
selector: "app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent implements OnInit {
public ngOnInit() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("./sw.js")
.then(registration => {
console.log(
"ServiceWorker registration successful with scope: ",
registration.scope
);
})
.catch(err => {
console.log("ServiceWorker registration failed: ", err);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment