问题
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