隐藏引导3莫代尔&安培; AngularJS重定向($ location.path) [英] Hide Bootstrap 3 Modal & AngularJS redirect ($location.path)

查看:113
本文介绍了隐藏引导3莫代尔&安培; AngularJS重定向($ location.path)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的引导模式3在我AngularJS应用程序对话框确认。当我隐藏模式和重定向模态的背景下仍然存在。

  $ scope.delete =功能(){
  DataService.delete()
    。然后(函数(){
      $(#删除)模式(隐藏)。
      $ location.path(/);
    });
}

我已经使用上隐藏回调试过

  $(#删除)。在('hidden.bs.modal',函数(){
  $ location.path(/);
}

但在这种延迟是很多。

有没有更好的方法来做到这一点?


解决方案

  

但在这种延迟是很多。


你可能忘了叫 $范围。$适用()。尝试将其更改为以下(如果延迟是唯一的问题)和延迟应该是正常的:

  $(#删除)。在('hidden.bs.modal',函数(){
    $ location.path(/);
    $ $范围适用于()。
});

这与交互角度被称为角外(在这种情况下,从jQuery的事件),所有code应该叫 $适用()

I'm using bootstrap 3 modal as a dialog confirmation in my AngularJS App. When i hide the modal and redirect the backdrop of the modal still remains.

$scope.delete = function () {   
  DataService.delete()
    .then(function () {
      $("#delete").modal("hide");
      $location.path("/");
    });
}

I have tried using the callback on hidden

$("#delete").on('hidden.bs.modal', function () { 
  $location.path("/");
}

But the delay in this is a lot.

Is there a better way to do this?

解决方案

But the delay in this is a lot.

You are probably forgetting to call $scope.$apply(). Try changing it to the following (if the delay is the only problem) and the delay should be normal:

$("#delete").on('hidden.bs.modal', function () {
    $location.path("/");
    $scope.$apply();
});

All code that is called outside Angular (in this case from jQuery event) that interacts with Angular should call $apply().

这篇关于隐藏引导3莫代尔&安培; AngularJS重定向($ location.path)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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