As a newcomer to angular, I successfully implemented a bootstrap popover around selected text using the following function:
$scope.highlight = function () {
var a = document.createElement("a");
a.setAttribute('tabindex', "0");
a.setAttribute('data-toggle','popover');
a.setAttribute("id","1");
a.setAttribute('data-content',"<button type='button' class='btn btn-default' ng-click='deleteLabel()'><small><span class='glyphicon glyphicon-remove'></span></small></button>");
a.setAttribute('data-html','True');
if (window.getSelection) {
var sel = window.getSelection()
var range = sel.getRangeAt(0).cloneRange();
range.surroundContents(a);
sel.removeAllRanges();
sel.addRange(range);
}
$timeout(function(){
$('[data-toggle="popover"]').popover();
}, 50);
};
Within the above code, the popover includes a button that should trigger the deleteLabel()
function upon click. This function is supposed to remove the element:
$scope.deleteLabel= function(){
alert("removing label");
var labelEl=document.getElementById("1");
labelEl.remove();
};
However, it seems like deleteLabel()
is not being executed when the button in the popover is clicked. Is there an issue with how I'm calling this function from within the popover?