简体   繁体   English

AngularJS bootstrap popover与另一个指令Object [object Object]没有方法'popover'

[英]AngularJS bootstrap popover with another directive Object [object Object] has no method 'popover'

I have a button that I would like to trigger a bootstrap popover. 我有一个按钮,我想触发一个bootstrap popover。 That works fine except that I need that popover to have another directive in it (basically popover contains a list of items). 这工作正常,除了我需要popover在其中有另一个指令(基本上popover包含项目列表)。

I have found this article http://tech.pro/tutorial/1360/bootstrap-popover-using-angularjs-compile-service but following it doesn't seem to work for me very well. 我发现这篇文章http://tech.pro/tutorial/1360/bootstrap-popover-using-angularjs-compile-service但是它似乎对我不起作用。

I made a custom directive 我做了一个自定义指令

.directive('popoverhtml', function ($compile) {
    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 以下是我的HTML标记

<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. 现在我没有传递任何自定义的HTML(如果有人知道如何做到这一点我也很欣赏这方面的一些指导)我只是试图让选项对象的content参数中的html硬编码显示popover 。

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. 根据我的googlefu,这可能意味着很多事情,我很欣赏一些关于Angular背景下可能意味着什么的见解。

Thank you! 谢谢!

EDIT: List of my JS includes. 编辑:我的JS列表包括。

<script src="//ajax.googleapis.com/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.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>    
<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/1.3.1/js/toastr.min.js"></script>   
<script src="//cdnjs.cloudflare.com/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 would recommend looking into AngularStrap Popovers . 我建议调查AngularStrap Popovers Generally, I'd recommend AngularUI, but AngularStrap supports template partials in popovers and AngularUI doesn't. 一般来说,我推荐使用AngularUI,但AngularStrap支持弹出窗口中的模板部分,而AngularUI则不支持。

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. 如果你选择使用AngularStrap,你可以编写一个HTML部分来显示在popover中,而partial可以包含你喜欢的任何指令,就像普通的Angular部分一样。

Loading jQuery prior to angular will solve the issue. 在angular之前加载jQuery将解决问题。 Technically the problem is loading jQuery twice (one from angular ie jqLite and the other is loaded later as separate js file) 从技术上讲,问题是加载jQuery两次(一个来自angular,即jqLit​​e,另一个稍后作为单独的js文件加载)

explained here https://stackoverflow.com/a/8792470 在这里解释https://stackoverflow.com/a/8792470

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM