为什么在承诺中设置 $window.location.href 不起作用? [英] Why setting $window.location.href does not work when set inside a promise?

查看:23
本文介绍了为什么在承诺中设置 $window.location.href 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向服务器发送请求,并希望在收到响应后有条件地重定向到另一个页面(非角度).因此导航发生在承诺的 then 部分内.

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.

我试过了:

$location.path(url)

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

没有任何效果.

但是如果我用 setTimeout(navigate,0) 包装这两个调用中的任何一个,就会发生重定向.
似乎在摘要周期中 Angular 守卫 url.

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.

推荐答案

在进行更改之后,在结束 promise 处理程序之前,尝试执行以下操作:

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

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

这应该填充更改.

这篇关于为什么在承诺中设置 $window.location.href 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆