I have created a directive using bootstrap custom popover. That works taking an input from a user for a group name and it has two buttons for apply that value to model and show that value on tooltip and a button to close the popover. I am using popover java script events , Problem is that single popover works perfectly but when I open another one this popover not closing itself. Need help in closing other popovers while one is open. Here is the plnk showing the directive.
Here is the code
var app = angular.module('myApp',[]);
app.directive('customEditPopover', function () {
return {
restrict: 'A',
template: '<span><i class="fa fa-tags" aria-hidden="true"></i></span>',
scope: {
'myModel': '=',
},
link: function (scope, el, attrs) {
scope.label = attrs.popoverLabel;
var btnsave = '#' + attrs.popoverSave;
var btncancel = '#' + attrs.popoverCancel;
var index = attrs.index;
$(el).tooltip({
title: '' + (scope.myModel == undefined) ? "" : scope.myModel,
container: 'body',
placement: 'top'
});
$(el).popover({
trigger: 'click',
html: true,
content: attrs.popoverHtml,
placement: attrs.popoverPlacement,
container: 'body'
})
.on('inserted.bs.popover', function (e) {
bindevents();
$('#popovertext' + index).val(scope.myModel);
}).on('hidden.bs.popover', function () {
Unbindevents();
});
function bindevents() {
$(btnsave).bind('click', function () {
var text = $('#popovertext' + index).val();
scope.myModel = text;
$(el).tooltip('hide')
.attr('data-original-title', text)
.tooltip('fixTitle')
toggle();
});
$(btncancel).bind('click', function () {
toggle();
});
}
function Unbindevents() {
$(btnsave).unbind('click');
$(btncancel).unbind('click');
}
function toggle() {
$(el).popover('hide');
$(el).click();
}
}
};
});
app.controller('MyController',['$scope',function($scope){
$scope.list=[
{
name:'ABC'
},
{
name:'DEF'
},
{
name:'GHI'
},
{
name:'KLM'
}
];
}]);
Need help closing other popover while opening next one.