Using InjectorFactory for routerProviders or routerProvidersHash can be automated?

坚强是说给别人听的谎言 提交于 2021-02-08 07:59:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!