当从ng-repeat中删除项目时,AngularJS UI Bootstrap popover outsideclick触发器会关闭弹出窗口 [英] AngularJS UI Bootstrap popover outsideclick trigger closes popover when item removed from ng-repeat

查看:74
本文介绍了当从ng-repeat中删除项目时,AngularJS UI Bootstrap popover outsideclick触发器会关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将AngularJS UI Bootstrap popover与外部点击触发器和popover模板一起使用.一切都按预期工作,除了我的模板内,我有一个ng-repeat,可以选择删除重复项中的一项.在所有这些工作正常的同时,将项目删除后,弹出式窗口即会关闭-好像认为我在弹出式窗口外单击一样.这是一个示范: http://plnkr.co/edit/vAk3y779eEmLSmIg9kb4?p=preview

I am using the AngularJS UI Bootstrap popover with outside click trigger and a popover template. It all works as expected, except inside my template I have an ng-repeat with an option to remove one of the items in the repeat. While this all works, as soon as the item is removed, the popover closes - it is as though it thinks I have clicked outside the popover. Here is a plunk to demonstrate: http://plnkr.co/edit/vAk3y779eEmLSmIg9kb4?p=preview

JS:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope, $sce) {
  $scope.dynamicPopover = {
    templateUrl: 'myPopoverTemplate.html',
  };


  $scope.checklistitems = [
    {check: false, text: "item 1"},
    {check: false, text: "item 2"},
    {check: false, text: "item 3"}
    ];

  $scope.delete = function (item) {
    var index;
    index = $scope.checklistitems.indexOf(item);

    $scope.checklistitems.splice(index, 1);
    console.log("yo delete: " + item.text)
  }

});

html:

<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.2.5.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="PopoverDemoCtrl">


    <span>some text to pad</span>

    <button uib-popover-template="dynamicPopover.templateUrl"
    type="button" class="btn btn-default"
    popover-placement="bottom"
    popover-trigger="outsideClick"
    >Popover With Template</button>

    <script type="text/ng-template" id="myPopoverTemplate.html">
        <div ng-repeat="item in checklistitems">
          {{item.text}}
          <button ng-click="delete(item)">delete</button>
        </div>
    </script>

</div>
  </body>
</html>

推荐答案

我遇到了同样的问题,但我发现弹出式窗口中的HTML发生更改时这是一个问题!

I had the same problem, I just found out it is a problem when the HTML in the popover changes!

我将ng-if更改为ng-show,并且单击按钮时弹出窗口没有关闭.

I changed my ng-ifs to ng-show and the popover didn't close when clicking on a button.

您的解决方案是标记已删除的项目并隐藏它们,并在弹出窗口关闭时进行真正的删除"!

Your solution could be to tag the deleted items and hide them, and make the real 'delete' when the popover closes!

像这样: http://plnkr.co/edit/2NifZtWtUuqh8CCBTALf?p=preview

这篇关于当从ng-repeat中删除项目时,AngularJS UI Bootstrap popover outsideclick触发器会关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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