AngularJS Bootstrap Popover Directive
HTML
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<div ng-app="customDirectives">
<div> <span custom-popover popover-html="<span style="color:red;">Some Popover Text</span>" popover-placement="bottom" popover-label="Label"></span>
</div>
<div> <span cust-popover popover-html="Some Poppy Text" popover-placement="bottom" myId="#myId" popover-label="Label"></span>
</div>
<div id="myId">Testing123</div>
</div>
JavaScript
customDirectives = angular.module('customDirectives', []);
customDirectives.directive('customPopover', function () {
return {
restrict: 'A',
template: '<span>{{label}}</span>',
link: function (scope, el, attrs) {
scope.label = attrs.popoverLabel;
$(el).popover({
trigger: 'click',
html: true,
content: attrs.popoverHtml,
placement: attrs.popoverPlacement
});
}
};
});
customDirectives.directive('custPopover', function () {
return {
restrict: 'A',
template: '<span>{{label}}</span>',
link: function (scope, el, attrs) {
scope.label = attrs.popoverLabel;
$(el).popover({
trigger: 'click',
html: true,
content: function() {
console.log('Test '+$(this).attr('myId'));
var id = $(this).attr('myId');
return $(id).html();
},
placement: attrs.popoverPlacement
});
}
};
});
angular.module('CustomComponents', ['customDirectives']);