对 routerProviders 或 routerProvidersHash 使用 InjectorFactory 可以自动化吗? [英] Using InjectorFactory for routerProviders or routerProvidersHash can be automated?
问题描述
我使用 runApp 和 namend 参数createInjector"引导 angular 来定义 routerStrategyrouterProviders"或routerProvidersHash".有什么方法可以像我希望在第一行中那样自动执行此定义?对于本地开发,我希望使用routerProvidersHash",而对于实时环境,我希望使用routerProvider".
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 :(
推荐答案
它是故意的,好像它是动态的,就像你建议的那样,然后它不能被优化.
It is const very much on purpose as if it is dynamic like you suggest then it can't be optimized.
我认为你可以做的是有两个注入器,一个用于开发,一个用于生产,并在调用 runApp 时决定使用哪一个.
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.
这篇关于对 routerProviders 或 routerProvidersHash 使用 InjectorFactory 可以自动化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!