简体   繁体   English

3秒后,角度$ timeout重定向

[英]angular $timeout redirect after 3secs

I'm trying to redirect back to the previous page using $timeout and $window.history.back(). 我正在尝试使用$ timeout和$ window.history.back()重定向回上一页。 So when form is submitted a message will show saying (thank you... bla bla) all good from here, but when redirecting back the $timeout doesn't seems to kick in. 因此,提交表单时会显示一条消息,表示(谢谢... bla bla)从此处一切正常,但是当重定向回$ timeout时似乎并没有生效。

<div class="thankyou" data-ng-show="vm.hideEnquiryForm">
            <h3><i class="fa fa-envelope fa-x2"></i> Thank you for enquiring, we will get back to you as soon as possible.</h3>
                <a href="javascript:history.back()">Return</a>
        </div>

vm.submitForm = function () {
        enquireService.postEnquireForm(vm)
            .then(function (response) {
                //$location.path(vm.returnUrl);
                //console.log($location.path() + ' '+ vm.returnUrl);

                if (!vm.hideEnquiryForm) {
                    vm.hideEnquiryForm = true;
                }
                $timeout(function () {
                   $window.history.back;
                }, 3000);
            })
    }

The are many way to do what you want... 有很多方法可以做您想要的...

The best way, in my opinion, could be using the interface exposed by your router (assuming that you are using a router)... 我认为最好的方法可能是使用路由器公开的接口(假设您使用的是路由器)...

this is a useful post based on top of UI.Router Angular - ui-router get previous state , so, you need just to go to the previous state using $state.go ; 这是一个基于UI的有用文章。Router Angular-ui-router获得先前状态 ,因此,您只需要使用$state.go进入先前状态$state.go

If you cannot do something like that, the only way is using the real history object... 如果您不能做这样的事情,那么唯一的方法就是使用真实history对象。

 vm.submitForm = function () { var returnUrl; enquireService .postEnquireForm(vm) .then(function (response) { var returnUrl = response.returnUrl; if (!vm.hideEnquiryForm) { vm.hideEnquiryForm = true; } return $timeout(window.history.back.bind(window), 3000); }); }; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM