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

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

    1. <legend id='oaM95'><style id='oaM95'><dir id='oaM95'><q id='oaM95'></q></dir></style></legend>
      <tfoot id='oaM95'></tfoot>
    2. <i id='oaM95'><tr id='oaM95'><dt id='oaM95'><q id='oaM95'><span id='oaM95'><b id='oaM95'><form id='oaM95'><ins id='oaM95'></ins><ul id='oaM95'></ul><sub id='oaM95'></sub></form><legend id='oaM95'></legend><bdo id='oaM95'><pre id='oaM95'><center id='oaM95'></center></pre></bdo></b><th id='oaM95'></th></span></q></dt></tr></i><div id='oaM95'><tfoot id='oaM95'></tfoot><dl id='oaM95'><fieldset id='oaM95'></fieldset></dl></div>

      拒绝承诺 Angular ui-router 后的 $state 转换

      $state transition after rejected promise Angular ui-router(拒绝承诺 Angular ui-router 后的 $state 转换)

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

        • <small id='PK5QU'></small><noframes id='PK5QU'>

            <bdo id='PK5QU'></bdo><ul id='PK5QU'></ul>
                <tbody id='PK5QU'></tbody>
                <tfoot id='PK5QU'></tfoot>
                <legend id='PK5QU'><style id='PK5QU'><dir id='PK5QU'><q id='PK5QU'></q></dir></style></legend>
              1. 本文介绍了拒绝承诺 Angular ui-router 后的 $state 转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在初始化控制器之前,我正在使用 Angular ui-router 并为我的一种状态设置了解析功能.我检索一些数据,循环并匹配 URL stateParam,如果找到匹配项,则将 promise 解析给控制器并在 promise 中返回该对象.这一切都很好.

                I'm using Angular ui-router and have a resolve function set up for one of my states, before the controller is initialized. I retrieve some data, loop through and match it up the URL stateParam, and if a match is found, resolve the promise to the controller and return that object in the promise. That's all working well.

                但是,如果找不到匹配项,我只想通过拒绝承诺并运行 $state.go('state');

                However, if a match isn't found I simply want to redirect to a different state by rejecting the promise and running $state.go('state');

                简单地说:

                deferred.reject();
                $state.go('state',{params: 'param'});
                

                但这似乎没有任何作用.控制器只是挂起,我没有得到任何控制台错误或任何东西.有什么想法吗?

                But this doesn't seem to do anything. The controller just hangs, and I get no console errors or anything. Any ideas?

                这个问题适用于 0.xx 版本,很多东西在 1.xx 版本中发生了变化

                推荐答案

                如果路由解析被拒绝,ui-router 应该抛出 $stateChangeError.你需要注意这个事件,并在那里触发你的状态转换.

                ui-router is supposed to throw a $stateChangeError if a route resolve is rejected. You need to watch for this event, and trigger your state transition there.

                根据维基:

                $stateChangeError - 在转换过程中发生错误时触发.重要的是要注意,如果您的解析函数中有任何错误(javascript 错误、不存在的服务等),它们通常不会抛出.您必须侦听此 $stateChangeError 事件才能捕获所有错误.

                $stateChangeError - fired when an error occurs during transition. It's important to note that if you have any errors in your resolve functions (javascript errors, non-existent services, etc) they will not throw traditionally. You must listen for this $stateChangeError event to catch ALL errors.

                https://github.com/angular-ui/ui-router/wiki#wiki-state-change-events

                正如评论中提到的@gustavohenke,放置此处理程序的好地方是您应用的主要 .run() 函数.

                As @gustavohenke mentioned in the comments, a good place to put this handler is your app's primary .run() function.

                这篇关于拒绝承诺 Angular ui-router 后的 $state 转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                    • <small id='PtyRp'></small><noframes id='PtyRp'>

                      <legend id='PtyRp'><style id='PtyRp'><dir id='PtyRp'><q id='PtyRp'></q></dir></style></legend>
                        <tbody id='PtyRp'></tbody>
                        • <bdo id='PtyRp'></bdo><ul id='PtyRp'></ul>
                          <tfoot id='PtyRp'></tfoot>

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