I created a popover for a checkbox click using angular directive. It works perfectly fine but the close button does work. Here is my example code.
myApp.directive('mypopover', function ($compile,$templateCache,$interpolate) {
var getTemplate = function (contentType,attrs) {
var template = '';
switch (contentType) {
case 'comment':
var template = "<div class=''>";
template += "<form><div class='form-group'>";
template += "<input type='hidden' value='"+attrs.value+"' name='documentationId' id='documentationId' />";
template += "<textarea style='width:250px;' class='form-control' name='doc_comment' id='doc_comment'>Selected for Re-Use in 2nd Trade Workflow.</textarea>";
template += "</div>";
template += "<div class='form-group'>";
template += "<input type='button' value='Close' class='btn btn-primary btn-xs' ng-click=\"closePopover()\" />";
template += "<input type='button' value='Comment' class='btn btn-primary btn-xs pull-right' />";
template += "</div></form><br>";
template += "</div>";
break;
}
return template;
}
return {
restrict: "EA",
link: function (scope, element, attrs) {
var popOverContent;
var d = new Date();
var mm = d.getMonth()+1;
popOverContent = getTemplate("comment",attrs);
var options = {
content: popOverContent,
placement: "right",
html: true,
date: scope.date,
title:"Date: "+mm+"/"+d.getDate()+"/"+d.getFullYear()
};
$(element).popover(options);
scope.closePopover = function() { //this block doesn't work
alert("called"); //does not return alert
}
}
};
});
html part of this is
<div class="checkbox checkbox-primary">
<input
type='checkbox'
ng-model='selectedDocIds'
mypopover
/>
</div>
I tried binding ng-click='closePopover()' function to main controller of this html but it doesn't work. I don't get error but just happen anything.
Can someone help me to have this ng-click event happening ?
Thanks
$compileto the template returned fromgetTemplate()to have it working. It is working in my plunker But I am having next problem, is uncheck of checkbox next time opens the popover. difference is I am unchecking the checkbox when popover is closed by clickingclosebutton. See my example here - Aashis Binod Khanal