I'm trying to redirect back to the previous page using $timeout and $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.
<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
;
If you cannot do something like that, the only way is using the real history
object...
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); }); };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.