My problem is that one of Angular modules, does not work correctly with the Safari browser.
I have following code :
@NgModule({
bootstrap: [ AppComponent ],
imports: [
BrowserAnimationsModule,
BrowserModule.withServerTransition({
appId: 'app'
}),
AppModule,
'navigator' in window && 'serviceWorker' in navigator ? ServiceWorkerModule.register('./ngsw-worker.js') : ServiceWorkerModuleMock
]
})
As you can see I want to conditionally import module. When I am using JIT compilation, this mechanism works well. Unfortunately, it is not working with AOT - ServiceWorkerModuleMock is imported regardless condition.
As a solution I was trying to play a little bit with ngDoBootstrap method:
@NgModule({
entryComponents: [ AppComponent ],
imports: [
BrowserAnimationsModule,
BrowserModule.withServerTransition({
appId: 'app'
}),
AppModule,
ServiceWorkerModule.register('./ngsw-worker.js')
]
})
export class BrowserAppModule {
constructor(private injector: Injector) {}
public ngDoBootstrap(appRef: ApplicationRef): void {
// console.log('navigator' in window && 'serviceWorker' in navigator);
appRef.bootstrap(AppComponent);
}
}
But so far I don't know how can I change module imported in @NgModule annotation here. Which method of which class should I use?
Maybe it is possible to change an instance of given service in the Injector? That solution would also satisfy me.