我正在将AngularJS UI Bootstrap popover与外部单击触发器和popover模板一起使用。一切都按预期工作,除了我的模板内,我有一个ng-repeat,可以选择删除重复项中的一项。虽然所有这些都有效,但是只要删除了该项目,弹出窗口就会关闭-好像我在弹出窗口外单击一样。这是一个简单的演示: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发生更改时这是一个问题!
我改变了我的ng-if
s到ng-show
和上一个按钮,点击时酥料饼没有关闭。
您的解决方案可能是标记已删除的项目并隐藏它们,并在弹出窗口关闭时进行真正的“删除”!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句