I found a solution when I can chage url with page reloading in AngularJS:
$window.location = "new_url";
$window.location.reload();
It has a by-effect - $window.location = "new_url"
changes state/route immidiately and you can discover loaded new controller's template and even discover network connections at controler's initialization, only then $window.location.reload()
code is executed that reloads the page.
I trided several ways like described here https://stackoverflow.com/a/26853786/551744
$state.go("state name", "state params", { reload: true });
but does not work for me, it does not reload the page.
This code does not work too:
$state.go("state name", "state params", { notify: false });
$state.reload();
I use this way, described here https://stackoverflow.com/a/25649813/551744:
$state.go("state name", "state params", { notify: false });
setTimeout(function() {
$window.location.reload();
}, 500);
bahaviour very close to needed (after url is changed state does not load new controller and template): $state.go("state name", "state params", { notify: false });
changes only url and $window.location.reload();
realods page with new url. But this way has by-effect: I need use setTimeout
to wait when url will be changed. I don't know why but it doesn't happen immidiately. I tried set 0ms, 50ms, 100ms, but sometimes url changes not fast enough and page realods with previous url.
How can I overcome:
- "setTimeout code" problem;
- or detect event when url is changed to force page reloading (it
can be a problem because code contains{ notify: false }
); - or other solution?
No comments:
Post a Comment