fix(aio): correctly reload page to apply ServiceWorker update (#16170)

Previously, due ot a limitation/bug in AoT compilation and `useValue`, the
`global` injected into `SwUpdateNotificationsService` was always undefined,
which prevented it from actually reloading the page after activating a
ServiceWorker update.

This commit fixes it by switching to `useFactory`, which works correctly with
AoT.
This commit is contained in:
Georgios Kalpakas 2017-04-19 21:08:51 +03:00 committed by Miško Hevery
parent 24c34385ee
commit 2ca6258a0f
2 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1,18 @@
import { ReflectiveInjector } from '@angular/core';
import { Global, globalProvider } from './global.value';
describe('Global', () => {
let value: any;
beforeEach(() => {
const injector = ReflectiveInjector.resolveAndCreate([globalProvider]);
value = injector.get(Global);
});
it('should be `window`', () => {
expect(value).toBe(window);
});
});

View File

@ -2,4 +2,7 @@ import { InjectionToken } from '@angular/core';
export const Global = new InjectionToken<Window>('global'); export const Global = new InjectionToken<Window>('global');
export const globalProvider = { provide: Global, useValue: window }; export const globalProvider = { provide: Global, useFactory: globalFactory };
export function globalFactory() {
return window;
}