简体   繁体   English

Angular和jQuery模态-未定义不是函数

[英]Angular and jQuery modal - undefined is not a function

I am creating a modal using Angular and jQuery, and I new to jQuery so I am using this directive angular+jQuery modal . 我正在使用Angular和jQuery创建modal ,而我是jQuery的新手,所以我在使用指令angular + jQuery modal

And I am getting this error: 我收到此错误:

undefined is not a function 未定义不是函数

For : 对于:

$(element).modal('show');

When changing it to 更改为

$element.modal('show');

The error changes to 错误变为

$element is not defined. 未定义$ element。

My code for the directive : 我的directive代码:

mymodal.directive('modal', function () {
    return {
      template: '<div class="modal fade">' + 
          '<div class="modal-dialog">' + 
            '<div class="modal-content">' + 
              '<div class="modal-header">' + 
                '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>' + 
                '<h4 class="modal-title">{{ title }}</h4>' + 
              '</div>' + 
              '<div class="modal-body" ng-transclude></div>' + 
            '</div>' + 
          '</div>' + 
        '</div>',
      restrict: 'E',
      transclude: true,
      replace:true,
      scope:true,
      link: function postLink(scope, element, attrs) {
        scope.title = attrs.title;

        scope.$watch(attrs.visible, function(value){
          if(value == true)
            $(element).modal('show');
          else
            $(element).modal('hide');
        });

        $(element).on('shown.bs.modal', function(){
          scope.$apply(function(){
            scope.$parent[attrs.visible] = true;
          });
        });

        $(element).on('hidden.bs.modal', function(){
          scope.$apply(function(){
            scope.$parent[attrs.visible] = false;
          });
        });
      }
    };
  });

Thanks for any help! 谢谢你的帮助! if there is more code needed I will post it. 如果需要更多代码,我将其发布。

Fixed Demo , guess your code is totally correct. 修复了演示 ,您的代码完全正确。

Why not working, as the bootstrap.min.js loaded failed. 为什么不起作用,因为bootstrap.min.js加载失败。

I just use https for bootstrap.min.js and update jQuery to 2.0.0, then it worked. 我只对bootstrap.min.js使用https并将jQuery更新到2.0.0,然后就可以了。

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

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