在启动应用程序之前等待回调请求 api angular
Await callback request api before start application angular
我需要在 bootstrap 应用程序之前从 Api 端点加载一些参数 Angular 1.
我有一个工厂,其中包含我的请求端点函数并保存在内存中。我需要使用这个工厂来执行我的角色。问题是我无法在 bootstrap 应用程序之前注入我的工厂。我无法创建其他具有相同想法的角色,我必须使用这个工厂来运行我的应用程序。
大家对这个案例有什么好的建议吗?谁已经需要这个案例?
谢谢大家
我认为您应该可以使用 angular-ui-路由器。您可以在路线上使用 resolve。这将强制 Angular 在继续渲染控制器之前解析数据。
您可以在 ui-router 中进入默认状态之前设置 resolve。
如果您使用 ngRoute
路由器,您可以使用解析函数来延迟视图及其控制器的实例化,直到数据从异步 API.
到达
resolve - {Object.<string, Function>=}
- An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the router will wait for them all to be resolved or one to be rejected before the controller is instantiated. If all the promises are resolved successfully, the values of the resolved promises are injected and $routeChangeSuccess event is fired. If any of the promises are rejected the $routeChangeError event is fired. For easier access to the resolved dependencies from the template, the resolve map will be available on the scope of the route, under $resolve
(by default) or a custom name specified by the resolveAs
property (see below). This can be particularly useful, when working with components as route templates.
我需要在 bootstrap 应用程序之前从 Api 端点加载一些参数 Angular 1.
我有一个工厂,其中包含我的请求端点函数并保存在内存中。我需要使用这个工厂来执行我的角色。问题是我无法在 bootstrap 应用程序之前注入我的工厂。我无法创建其他具有相同想法的角色,我必须使用这个工厂来运行我的应用程序。
大家对这个案例有什么好的建议吗?谁已经需要这个案例?
谢谢大家
我认为您应该可以使用 angular-ui-路由器。您可以在路线上使用 resolve。这将强制 Angular 在继续渲染控制器之前解析数据。 您可以在 ui-router 中进入默认状态之前设置 resolve。
如果您使用 ngRoute
路由器,您可以使用解析函数来延迟视图及其控制器的实例化,直到数据从异步 API.
resolve - {Object.<string, Function>=}
- An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the router will wait for them all to be resolved or one to be rejected before the controller is instantiated. If all the promises are resolved successfully, the values of the resolved promises are injected and $routeChangeSuccess event is fired. If any of the promises are rejected the $routeChangeError event is fired. For easier access to the resolved dependencies from the template, the resolve map will be available on the scope of the route, under$resolve
(by default) or a custom name specified by theresolveAs
property (see below). This can be particularly useful, when working with components as route templates.