【问题标题】:Angular UI bootstrap modal redirect after function using location.path使用 location.path 函数后的 Angular UI 引导模式重定向
【发布时间】:2016-02-22 03:10:33
【问题描述】:

用户在此模式中单击“确定”后,应将他们带到另一个页面。我的 app.js 中有路由,控制器中有函数,还有模态视图,但它只是继续将用户带到“#/home”,而没有其他地方。不知道为什么会这样或如何解决它。有任何想法吗?

我的代码:

视图中的模态:

<!-- Recur Confirm Modal -->
<div class="modal fade" id="recurConfirm" tabindex="-1" role="dialog" aria-labelledby="recurConfirm" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <p>Congratulations! Your recurring claim has been submitted and will be reviewed by our customer service team.  We’ll contact you if we have any questions or concerns with your submission. If you have questions about your submission, please contact our customer service team at (800) 669-3539 or <a class="naviaLink" href="mailto:customerservice@naviabenefits.com">customerservice@naviabenefits.com</a>.</p>
            </div>
            <div class="modal-footer">
                <input type="button" class="naviaBtn naviaBlue" data-dismiss="modal" value="okay" ng-click="recurOkay()">
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

我的控制器功能(当用户保存数据并进行重定向时触发此模式):

$scope.recurOkay = function() {
    $('#recurConfirm').modal('hide');
    $('body').removeClass('modal-open');
    $('.modal-backdrop').remove();   
    $location.path('/#/pptHome');
};

而且我的路线很标准。

【问题讨论】:

    标签: html angularjs twitter-bootstrap routing angular-ui-bootstrap


    【解决方案1】:

    $location.path 方法仅接受 URL string,该字符串不应包含 #。基本上,此方法将在URL 中的# 之后附加给定的string。

    因此,在您的情况下,$location.path('/#/pptHome'); 在执行后会重定向到路由引擎无法识别的 URL http://localhost/#/#/pptHome,并重定向到备用 URL。

    要解决此问题,请执行以下操作。

    $location.path('/pptHome'); //will redirect to `/#/pptHome`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多