Close AngularStrap popover

When I press the button, a popover appears, which can be closed if you press the button inside the popover. However, if you press another button to open a popover, you will see two popovers at the same time, and I want to save only one.

I tried using the trigger "focus", but it closes the popover, if I am in the text box inside the popover, I expected this trigger to be called when you click outside the popover.

Any idea for this? Can $ hide, $ show methods be called from the controller?

+4
source share
5 answers

, , , . , popover popover ( data-template, ), , ( , ), . : , popovers popover .

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();
                        }
                    }
                    );
                });
            }
        }
    }
);

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

ng-click="$hide()" popover. :.

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

, , popover-, popover.

+4

This should be an old question, in the latest version of angular -strap, in this case you can use the new attribute: auto-close='1'

+2
source

There is a problem in the angular -strap github project that requests exactly the function you want.

However, at the moment I am writing this answer, it is still open.

0
source
trigger : 'focus' ,

worked for me on the same problem

-1
source

Source: https://habr.com/ru/post/1528792/


All Articles