angular/aio/src/main.ts
George Kalpakas 650c6e56ec fix(aio): wait for the app to stabilize before registering the SW (#23093)
This commit also waits for the app to stabilize, before starting to
check for ServiceWorker updates. This avoids setting up a long timeout,
which would prevent the app from stabilizing and thus cause issues with
Protractor.

PR Close #23093
2018-03-30 15:27:21 -07:00

20 lines
682 B
TypeScript

import { enableProdMode, ApplicationRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import 'rxjs/add/operator/first';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
if (environment.production && 'serviceWorker' in (navigator as any)) {
const appRef: ApplicationRef = ref.injector.get(ApplicationRef);
appRef.isStable.first(v => v).subscribe(() => {
(navigator as any).serviceWorker.register('/worker-basic.min.js');
});
}
});