I'm trying to load Firebase Remote Config using "APP_INITIALIZER" token.
That's my code in app.module.ts:
...
export function initSynchronousFactory(environmentService: EnvironmentService) {
return () => {
console.log('initSynchronousFactory');
return environmentService.init();
};
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
...
provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
provideAuth(() => initializeAuth(getApp(), { persistence: indexedDBLocalPersistence })),
// provideAuth(() => getAuth()),
provideDatabase(() => getDatabase()),
provideStorage(() => getStorage()),
provideFirestore(() => getFirestore()),
provideFunctions(() => getFunctions()),
provideRemoteConfig(() => {
const remoteConfig = getRemoteConfig(getApp());
remoteConfig.settings.minimumFetchIntervalMillis = isDevMode() ? 10000 : 43200000;
fetchAndActivate(remoteConfig);
return remoteConfig;
}),
],
providers: [
{ provide: APP_INITIALIZER, useFactory: initSynchronousFactory, deps:[EnvironmentService], multi: true },
],
bootstrap: [AppComponent],
})
export class AppModule {}
And this is my environment.service.ts:
import { Injectable, Injector, isDevMode } from '@angular/core';
import { fetchAndActivate, getString, RemoteConfig } from '@angular/fire/remote-config';
@Injectable({
providedIn: 'root'
})
export class EnvironmentService {
constructor(private remoteConfig: RemoteConfig) {
console.log('EnvironmentService constructor')
}
init() {
console.log('EnvironmentService init')
}
}
I got this error and the app doesn't start:
ERROR Error: The APP_INITIALIZER that is "making" isSupported() sync for the sake of convenient DI has not resolved in this
context. Rather than injecting RemoteConfig in the constructor, first ensure that RemoteConfig is supported by calling
`await isSupported()`, then retrieve the instance from the injector manually `injector.get(RemoteConfig)`.
I can't see the "initSynchronousFactory" log.
This is the complete log:
If I remove RemoteConfig It work, but I have need to import data from Firebase.
I can't understand where the problem is.
Maybe the Remote module hasn't been imported yet?
Can I use module in "import" directive in APP_INITIALIZER function?