加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用$dialog多次打开相同的对话框

发布时间:2020-12-17 17:19:29 所属栏目:安全 来源:网络整理
导读:我回答这个问题’ AngularJS – open controller in a dialog (template loaded dynamically)‘时创建了 this plnkr. 所有示例应用程序都会基于模板启动一个对话框,并带有自己的控制器.对话框第一次启动时,一切都按预期工作.但是,如果我尝试重新启动对话框,
我回答这个问题’ AngularJS – open controller in a dialog (template loaded dynamically)‘时创建了 this plnkr.

所有示例应用程序都会基于模板启动一个对话框,并带有自己的控制器.对话框第一次启动时,一切都按预期工作.但是,如果我尝试重新启动对话框,在解除它后,会显示模态背景但没有对话框.在javascript控制台中,您可以看到$dialog.open()返回的promise上的then方法被立即调用,但不删除背景,也不会报告错误.我完全不知所措.

可以在angular-ui bootstrap documentation page上重复打开和关闭对话框.

我哪里做错了?

HTML:

<!DOCTYPE html>
<html ng-app="plnkr">

  <head>
    <link data-require="bootstrap-css@*" data-semver="2.3.2" rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" />
    <script data-require="angular.js@1.0.7" data-semver="1.0.7" src="http://code.angularjs.org/1.0.7/angular.min.js"></script>
    <script data-require="ui-bootstrap@0.3.0" data-semver="0.3.0" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.3.0.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body>
    <div ng-view></div>
  </body>

</html>

JS:

app.controller("DemoCtl",["$scope","$dialog",function($scope,$dialog){
  $scope.launch = function() {
    var d = $dialog.dialog({
      backdrop: true,keyboard: true,backdropClick: true,templateUrl: "dialog.html",controller: "DialogCtl"
    });

    d.open().then(function(result) { console.log("d.open().then"); });
  };
}]);

解决方法

我发现了这个问题.它与使用< a>有关.标记以打开对话框.点击< a> tag会导致触发位置更改.该对话框通过关闭自身来处理位置更改,如下所示.

this.handleLocationChange = function() {
    self.close();
  };

我不确定为什么在首次点击< a>时不会发生这种情况.标签,但它肯定发生在所有后续调用.

您可以在此plunker中看到,如果您使用按钮,则每次都会正确打开.

希望这可以帮助!我会试着弄清楚它为什么不会在第一时间破坏.

编辑

位置变化实际上非常糟糕.它似乎是循环的,我认为是10个消化的最大角度.仍然不确定为什么它不会在第一次点击时进行位置更改.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读