Nikola Kotur
Nikola Kotur

Reputation: 1994

How to close all other bootstrap popovers in AngularJS

Is there the AngularJS way to close other popovers on creating a new one. For example, this code:

http://plnkr.co/edit/wx7KbFDb9du6TnaFioy2?p=preview

I can do it by falling back to jQuery, is there any other way?

Upvotes: 0

Views: 257

Answers (1)

hassassin
hassassin

Reputation: 5054

Since popovers could potentially exist anywhere in your dom tree. You would need to either create your very own publisher subsriber system or use the built in $broadcast and $on methods for angularjs.

When you have a popover show up you just need to call $rootScope.$broadcast(the popover you just opened) and have a $scope.$on in all of the popover places that listen to this event and close if they are open.

Check out the docs for more information http://docs.angularjs.org/api/ng.$rootScope.Scope#methods_$on

Hope this helped

Upvotes: 1

Related Questions