<i id='tdEgC'><tr id='tdEgC'><dt id='tdEgC'><q id='tdEgC'><span id='tdEgC'><b id='tdEgC'><form id='tdEgC'><ins id='tdEgC'></ins><ul id='tdEgC'></ul><sub id='tdEgC'></sub></form><legend id='tdEgC'></legend><bdo id='tdEgC'><pre id='tdEgC'><center id='tdEgC'></center></pre></bdo></b><th id='tdEgC'></th></span></q></dt></tr></i><div id='tdEgC'><tfoot id='tdEgC'></tfoot><dl id='tdEgC'><fieldset id='tdEgC'></fieldset></dl></div>

  • <legend id='tdEgC'><style id='tdEgC'><dir id='tdEgC'><q id='tdEgC'></q></dir></style></legend>
      <tfoot id='tdEgC'></tfoot>

      <small id='tdEgC'></small><noframes id='tdEgC'>

          <bdo id='tdEgC'></bdo><ul id='tdEgC'></ul>

        Angular ui-router 中的 Promise 依赖解析顺序

        时间:2023-09-30

        <small id='9gTQC'></small><noframes id='9gTQC'>

          <i id='9gTQC'><tr id='9gTQC'><dt id='9gTQC'><q id='9gTQC'><span id='9gTQC'><b id='9gTQC'><form id='9gTQC'><ins id='9gTQC'></ins><ul id='9gTQC'></ul><sub id='9gTQC'></sub></form><legend id='9gTQC'></legend><bdo id='9gTQC'><pre id='9gTQC'><center id='9gTQC'></center></pre></bdo></b><th id='9gTQC'></th></span></q></dt></tr></i><div id='9gTQC'><tfoot id='9gTQC'></tfoot><dl id='9gTQC'><fieldset id='9gTQC'></fieldset></dl></div>

            <bdo id='9gTQC'></bdo><ul id='9gTQC'></ul>

            <tfoot id='9gTQC'></tfoot>

                <legend id='9gTQC'><style id='9gTQC'><dir id='9gTQC'><q id='9gTQC'></q></dir></style></legend>
                    <tbody id='9gTQC'></tbody>

                  本文介绍了Angular ui-router 中的 Promise 依赖解析顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经设置了一个顶级控制器,它仅在成功解决承诺(由 Config 工厂返回)时实例化.该承诺基本上是下载 Web 应用配置,带有 RESTful 端点等.

                  I have set up a top-level controller that is instantiated only when a promise (returned by a Config factory) is successfully resolved. That promise basically downloads the Web app configuration, with RESTful endpoints and so on.

                  $stateProvider
                    .state('app', {
                      url: '/',
                      templateUrl: 'views/_index.html',
                      controller: 'MainCtrl',
                      resolve: {
                        config: 'Config'
                      }
                    });
                  

                  此设置允许我在任何较低的控制器有机会使用它之前断言配置已正确加载.

                  This setup allows me to kind-of assert that the configuration is properly loaded before any lower controller gets a chance to use it.

                  现在我需要在更深的嵌套控制器中注入另一个 factory,它使用 Config 并且仅在它被解析时才起作用(看它像 $resource 包装器,需要一些 Web 服务 URL).如果我这样做:

                  Now I need to inject, in a deeper nested controller, another factory that uses Config and only works when it is resolved (look at it like a $resource wrapper that needs some Web service URLs). If I do:

                  $stateProvider
                    .state('app.bottom.page', {
                      url: '/bottom/page',
                      templateUrl: 'views/_a_view.html',
                      controller: 'BottomLevelCtrl',
                      resolve: {
                        TheResource: 'MyConfigDependingResource'
                      }
                    });
                  

                  看起来 resolve 评估顺序不是从上到下,而是从下到上,因此:

                  it looks like the resolve evaluation order does not follow the controller hierarchy from top to bottom, but from bottom to top, therefore:

                  1. app.bottom.page 已输入
                  2. ui-router尝试解析MyConfigDependingResource,但是注入失败,因为 Config 从未被初始化过
                  3. ui-router 解析因错误而停止(甚至没有抛出 Error,但这是另一个问题),并且 Config 是从未被顶级控制器初始化
                  1. app.bottom.page is entered
                  2. ui-router attempts to resolve MyConfigDependingResource, but the injection fails, because Config has never been initialized
                  3. The ui-router resolution stops because of an error (without even throwing Errors, but that's another issue), and Config is never initialized by the top level controller

                  为什么 ui-router 以相反的顺序解析依赖关系?如何轻松解决我的 TheResource 对象 顶级 MainCtrl 已解决 Config (不依赖 $inject,当然)?

                  Why is ui-router resolving dependencies in a reverse order? How can I easily resolve my TheResource object after the top level MainCtrl has resolved Config (without relying on $inject, of course)?

                  更新:从 这个 plnkr 的日志你可以看到只有在嵌套控制器开始自己的解析过程后才会尝试顶级 resolve.

                  UPDATE: from this plnkr's log you can see that the top level resolve is attempted only after the nested controller has started its own resolving process.

                  推荐答案

                  类似于@Kasper Lewau 的回答,可以指定对单个状态的解析的依赖.如果您的一个解析依赖于同一解析块中的一个或多个解析属性.在我的情况下 checkS 依赖于另外两个解决方案

                  Similarly to @Kasper Lewau's answer, one may specify a dependency on resolves withing a single state. If one of your resolves depends on one or more resolve properties from the same resolve block. In my case checkS relies on two other resolves

                  .state('stateofstate', {
                      url: "/anrapasd",
                      templateUrl: "views/anrapasd.html",
                      controller: 'SteofsteCtrl',
                      resolve: {
                          currU: function(gamMag) {
                              return gamMag.checkWifi("jabadabadu")
                          },
                          userC: function(gamUser, $stateParams) {
                              return gamUser.getBipi("oink")
                          },
                          checkS: ['currU', 'userC', 'gamMag', function(currU, userC, gamMag) {
                              return gamMag.check(currU, userC);
                          }]
                      }
                  })
                  

                  <小时>

                  **PS:**检查以下文档 了解更多关于 resolve 的内部工作原理.


                  **PS: **Check the "Resolves" section of the following document for more details about the inner-workings of resolve.

                  这篇关于Angular ui-router 中的 Promise 依赖解析顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使 Angular ui-router 的父状态在状态更改时始终执行控制器代码? 下一篇:推迟 Angular UI 路由器 $stateChangeStart 直到收到服务器授权响应

                  相关文章

                  • <bdo id='e2ZlA'></bdo><ul id='e2ZlA'></ul>
                  <tfoot id='e2ZlA'></tfoot>
                  <i id='e2ZlA'><tr id='e2ZlA'><dt id='e2ZlA'><q id='e2ZlA'><span id='e2ZlA'><b id='e2ZlA'><form id='e2ZlA'><ins id='e2ZlA'></ins><ul id='e2ZlA'></ul><sub id='e2ZlA'></sub></form><legend id='e2ZlA'></legend><bdo id='e2ZlA'><pre id='e2ZlA'><center id='e2ZlA'></center></pre></bdo></b><th id='e2ZlA'></th></span></q></dt></tr></i><div id='e2ZlA'><tfoot id='e2ZlA'></tfoot><dl id='e2ZlA'><fieldset id='e2ZlA'></fieldset></dl></div>

                    <legend id='e2ZlA'><style id='e2ZlA'><dir id='e2ZlA'><q id='e2ZlA'></q></dir></style></legend>

                  1. <small id='e2ZlA'></small><noframes id='e2ZlA'>