Close AngularStrap popover

前端 未结 5 976
半阙折子戏
半阙折子戏 2021-01-06 11:33

When I click a button, it appears a popover which can be closed if you click the button inside the popover. However, if you click another button to open a popover, you will

相关标签:
5条回答
  • 2021-01-06 11:47
    trigger : 'focus' ,
    

    worked for me on the same issue

    0 讨论(0)
  • 2021-01-06 11:49

    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.

    0 讨论(0)
  • 2021-01-06 11:50

    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
    
    0 讨论(0)
  • 2021-01-06 12:02

    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.

    0 讨论(0)
  • 2021-01-06 12:05

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

    0 讨论(0)
提交回复
热议问题