I have a button that I would like to trigger a bootstrap popover. That works fine except that I need that popover to have another directive in it (basically popover contains a list of items).
I have found this article but following it doesn't seem to work for me very well.
I made a custom directive
.directive('popoverhtml', function ($pile) {
return {
restrict: 'A',
transclude: true,
template: "<span ng-transclude></span>",
scope: {
},
link: function (scope, element, attrs) {
console.log($(element));
var options = {
content: "<br><br>Hey",
placement: "right",
html: true,
title: "HEY",
trigger: "click"
};
$(element).popover(options);
}
}
and the following is my HTML mark up
<button type="button" class="btn btn-primary btn-small" popoverHTML><i class="icon-white icon-plus"></i></button>
For now I am not passing any custom html to it (if anybody knows how to do that I'd appreciate some guidance on this as well) I am just trying to get the popover appear with the html hardcoded in content
param of the options object.
However I am getting the following error as soon as the view with the button loads (before I click on the button)
TypeError: Object [object Object] has no method 'popover'
According to my googlefu this can mean quite a lot of things and I would appreciate some insight on what that could mean in the context of Angular.
Thank you!
EDIT: List of my JS includes.
<script src="//ajax.googleapis/ajax/libs/angularjs/1.1.5/angular-resource.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.4.0.js"></script>
<script src="//ajax.googleapis/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare/ajax/libs/toastr.js/1.3.1/js/toastr.min.js"></script>
<script src="//cdnjs.cloudflare/ajax/libs/angular-strap/0.7.4/angular-strap.min.js"></script>
<script src="js/admin-angular.js"></script> <-- My custom include
<script src="js/admin-jquery.js"></script> <-- My custom include
<script src="js/jquery.watermark.min.js"></script>
<script src="js/jquery.base64.js"></script>
I have a button that I would like to trigger a bootstrap popover. That works fine except that I need that popover to have another directive in it (basically popover contains a list of items).
I have found this article http://tech.pro/tutorial/1360/bootstrap-popover-using-angularjs-pile-service but following it doesn't seem to work for me very well.
I made a custom directive
.directive('popoverhtml', function ($pile) {
return {
restrict: 'A',
transclude: true,
template: "<span ng-transclude></span>",
scope: {
},
link: function (scope, element, attrs) {
console.log($(element));
var options = {
content: "<br><br>Hey",
placement: "right",
html: true,
title: "HEY",
trigger: "click"
};
$(element).popover(options);
}
}
and the following is my HTML mark up
<button type="button" class="btn btn-primary btn-small" popoverHTML><i class="icon-white icon-plus"></i></button>
For now I am not passing any custom html to it (if anybody knows how to do that I'd appreciate some guidance on this as well) I am just trying to get the popover appear with the html hardcoded in content
param of the options object.
However I am getting the following error as soon as the view with the button loads (before I click on the button)
TypeError: Object [object Object] has no method 'popover'
According to my googlefu this can mean quite a lot of things and I would appreciate some insight on what that could mean in the context of Angular.
Thank you!
EDIT: List of my JS includes.
<script src="//ajax.googleapis./ajax/libs/angularjs/1.1.5/angular-resource.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.4.0.js"></script>
<script src="//ajax.googleapis./ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare./ajax/libs/toastr.js/1.3.1/js/toastr.min.js"></script>
<script src="//cdnjs.cloudflare./ajax/libs/angular-strap/0.7.4/angular-strap.min.js"></script>
<script src="js/admin-angular.js"></script> <-- My custom include
<script src="js/admin-jquery.js"></script> <-- My custom include
<script src="js/jquery.watermark.min.js"></script>
<script src="js/jquery.base64.js"></script>
Share
edited Aug 16, 2013 at 15:49
americanslon
asked Aug 15, 2013 at 14:42
americanslonamericanslon
4,2985 gold badges35 silver badges62 bronze badges
5
- 1 Not really an answer, but have you tried the angular directive for Bootstrap: angular-ui.github.io/bootstrap – seridis Commented Aug 15, 2013 at 15:18
- +1 angular UI bootstrap popovers are very simple and they'll allow you to use directives in the popover. – Jon7 Commented Aug 15, 2013 at 15:19
- Their popover directive is actually where I started...I am not seeing an example showing how to use your custom directives (or any directives) in the popup. I feel like I am missing something very obvious. Thanks guys. – americanslon Commented Aug 15, 2013 at 15:48
- @Jon7 could you elaborate. I didn't see any examples of how to include the custom directives in the popover html. Thanks. – americanslon Commented Aug 16, 2013 at 13:47
- So sorry! I was thinking of AngularStrap. AngularUI doesn't have this feature. I elaborated more in my answer. – Jon7 Commented Aug 16, 2013 at 14:02
2 Answers
Reset to default 3I would remend looking into AngularStrap Popovers. Generally, I'd remend AngularUI, but AngularStrap supports template partials in popovers and AngularUI doesn't.
If you do go with AngularStrap, you can just write an HTML partial to be displayed in the popover and that partial can include whatever directives you like just like a normal Angular partial.
Loading jQuery prior to angular will solve the issue. Technically the problem is loading jQuery twice (one from angular i.e. jqLite and the other is loaded later as separate js file)
explained here https://stackoverflow./a/8792470