Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 840
Pavel Voronin Avatar asked Oct 16 '14 13:10

Pavel Voronin


1 Answers

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

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

That should populate the changes.

like image 175
vtortola Avatar answered Oct 02 '22 13:10

vtortola