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:
parent
24c34385ee
commit
2ca6258a0f
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -2,4 +2,7 @@ import { InjectionToken } from '@angular/core';
|
|||
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue