Why setting $window.location.href does not work when set inside a promise?

吃可爱长大的小学妹 提交于 2019-12-08 16:12:30

问题


I send request to the server and want conditionally redirect to another page (not angular) after response is received. Thus navigation happens inside then part of a promise.

I tried:

$location.path(url)

and

$window.location.href = url;
$windo.location.reload();

nothing works.

But if I wrap either of these two calls with setTimeout(navigate,0) redirection occurs.
Seems like Angular guards url during digest cycle.

Can anyone clarify or share the links explaining what really happens.


回答1:


After doing the change, and before ending the promise handler, try doing:

$scope.$$phase || $scope.$apply();

That should populate the changes.



来源:https://stackoverflow.com/questions/26406338/why-setting-window-location-href-does-not-work-when-set-inside-a-promise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!