Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

ngsw pwa how to check version update

// You will probably need to tell the service worker to check the server for updates, I usually use a service for this:

export class UpdateService {

  constructor(public updates: SwUpdate) {
    if (updates.isEnabled) {
      interval(6 * 60 * 60).subscribe(() => updates.checkForUpdate()
        .then(() => console.log('checking for updates')));
    }
  }

  public checkForUpdates(): void {
    this.updates.available.subscribe(event => this.promptUser());
  }

  private promptUser(): void {
    console.log('updating to new version');
    this.updates.activateUpdate().then(() => document.location.reload()); 
  }
// In your app-component.ts:

  constructor(private sw: UpdateService) {
    // check the service worker for updates
    this.sw.checkForUpdates();
  }
// For whatever reason, Angular sometimes does not register the service worker properly. So you can modify `main.ts` :
// Replace:

// platformBrowserDynamic().bootstrapModule(AppModule);
// With:

platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
  if ('serviceWorker' in navigator && environment.production) {
    navigator.serviceWorker.register('ngsw-worker.js');
  }
}).catch(err => console.log(err));
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to set value of multiselect dropdown for reactive forms in angular 6 
Typescript :: running same tests against different browsers 
Typescript :: 0 
Typescript :: nativescript alert 
Typescript :: element of an array is the same as any of the previous elements pandas 
Typescript :: mkdir windows 
Typescript :: error NG6002: Appears in the NgModule.imports of DashboardModule, but could not be resolved to an NgModule class. 
Typescript :: react-i18next bold text 
Typescript :: In default Laravel installation, what is the default API Rate Limit? In other words, how many requests can be done in one minute? 
Typescript :: to move a directory with its contents in terminal in linux 
Typescript :: js Validating nested promises 
Typescript :: exits adn copy file in java 
Typescript :: $clients = User::query()-where("type","client" ) 
Typescript :: typescript directory structure 
Typescript :: number validation in typescript 
Typescript :: typescript add class to element 
Typescript :: typeorm transactions example 
Typescript :: typescript object of objects 
Typescript :: angular conditional directives 
Typescript :: What are the components of the environment? Explain it along with the examples. 
Typescript :: storing user name and password ofr hosts in ansible playbooks 
Cpp :: c++ get file content 
Cpp :: a c++ program to set a countdown timer 
Cpp :: c++ hello word 
Cpp :: c++ pause program 
Cpp :: c++ colour text 
Cpp :: compile multiple files C++ linux 
Cpp :: C++ Kelvin to Celsius 
Cpp :: retourner pointeur de type qstringlist qt 
Cpp :: xmake run with arg 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =