[英]$location.path takes time to work after bootstrap modal hide (hide.bs.modal) event is fired
// show mymodal
// register an event to route to a different page once modal is closed
$('#myModal').on('hide.bs.modal', function() {
if ($location.path() == '/') {
$location.path('/ser/mynewpath');
alert("fired"); // just to check the event was fired
}
});
// open the modal
$('#myModal').modal('show');
我正在使用JavaScript调用引导程序模式#myModal。 关闭模态后,我想将页面定向到其他路径。 问题是关闭模式后需要30秒-1分钟的时间才能定向页面。 我添加了警报,以检查事件是否迟到了,但是当我关闭模式时会收到警报,但是页面是经过漫长的等待之后才定向的。
有时,当我单击其他位置时,它将被触发。 但这并非总是会发生-有时漫长的等待是不可避免的。
我最初的猜测是因为我正在使用引导程序模态并使用$ location,所以当模态关闭时,angular可能无法检测到它。 但是现在看来,这似乎是愚蠢的猜测。 我还尝试将事件触发器更改为“ hidden.bs.modal”,但得到的结果相同。
我将尝试添加angular $ modal,看看是否能解决,将发布更新。 但是与此同时,我很高兴了解这种设置延迟的原因。
谢谢。
由于是jquery
事件,因此angular
不会立即意识到此事件。 它必须等到下一个摘要周期,这才导致延迟。 您尝试使用$scope.$apply
$scope.$apply(function() {
if ($location.path() == '/') {
$location.path('/ser/mynewpath');
alert("fired"); // just to check the event was fired
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.