Close AngularStrap popover

若如初见. 提交于 2019-11-30 22:08:43

OK, I am pretty sure this is a terrible hack, but here goes. Assuming your popover templates all use the popover class (if you aren't using a custom template with the data-template attribute, they should), and they're siblings of the button that triggers them (if you haven't mucked with the container attribute, they are), you can apply the following directive to your popover buttons. Note: this assumes that the parent elements of your popovers and popover buttons have unique ids.

angular.module('yourApp.directives', []).directive('rmPopovers',
    function($document,$rootScope,$timeout,$popover) {
        return {
            restrict: 'EA',
            link : function(scope, element, attrs) {
                var $element = $(element);
                $element.click(function() {
                    $('.popover').each(function(){
                        var $this = $(this);
                        if($this.parent().attr('id') != $element.parent().attr('id'))
                        {
                            $this.scope().$hide();
                        }
                    }
                    );
                });
            }
        }
    }
);

And then

<button type="button" bs-popover rm-popovers [your data attribs here]>Button!</button

Try to add ng-click="$hide()" on the dismissable element of the popover. I.E.:

<a class="btn btn-primary"  ng-click="$hide()">Close</a>

It's not included in the documentation but it works for me, iff you use data-template for popover content, haven't tried with other opened popover yet.

This should be an old question, in latest version of angular-strap, a new attribute could be used in this case: auto-close='1'

There is an issue in the angular-strap github project which asks exactly the feature you want.

Nevertheless, at the moment I'm writing this answer, it's still open.

yugal
trigger : 'focus' ,

worked for me on the same issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!