问题
I'm bootstrap angular with runApp and the namend Parameter "createInjector" to define the routerStrategy "routerProviders" or "routerProvidersHash". Is there any way to automate this definition like i wish to do this in my first line? For local development i wish to use "routerProvidersHash" and for live environment is wanna use the "routerProvider".
const List<Provider<Object>> routerStrategy = Environment.isLive() ? routerProviders : routerProvidersHash;
@GenerateInjector([
routerStrategy,
ClassProvider(Client, useClass: BrowserClient),
])
final InjectorFactory injector = self.injector$Injector;
void main() {
runApp(ng.AppComponentNgFactory, createInjector: injector);
}
The problem is, that this value need to be a const, but then i can not create the constant like this. I have no idea to make this more flexible :(
回答1:
It is const very much on purpose as if it is dynamic like you suggest then it can't be optimized.
What I think you can do is have two injectors one for devel, and one for prod and decide which one to use when you call runApp.
来源:https://stackoverflow.com/questions/56741536/using-injectorfactory-for-routerproviders-or-routerprovidershash-can-be-automate