javascript - TypeError : $(. ..).carousel 不是函数

标签 javascript jquery angularjs twitter-bootstrap carousel

我知道很多问题都问过这个问题,但最常见的答案是未加载 jQuery 对我不起作用。看来我的 jQuery 正在正确加载(版本 1.10.2)。 我正在尝试运行以下代码(即使在控制台中也尝试过,因此加载问题不会保留): <code>$('.carousel').on('mouseenter',function(){ $( this ).carousel();})</code>

Bootstrap 轮播本身运行良好。就在我尝试动态初始化它时,它不起作用。 (我刚开始使用 angular 和 bootstrap,所以我可能在这里遗漏了一些非常简单的东西。) 我正在为我的应用程序使用 angular js 和 bootstrap。

编辑: 这是我的 html 代码:

<div class="row" ng-controller="ItemGallery" style="padding-top:30px;">
    <div class="col-md-4 item_card" ng-repeat="item in item_array">
        <a href="{{'/product/id='+item.product_id}}" class="thumbnail">
            <div id="{{'carousel_'+item.product_id}}" class="carousel slide" data-ride="carousel" data-interval="false">
                <div class="carousel-inner" role="listbox">
                    <div class="item active">
                        <img src="{{item.thumbnail}}" alt="{{item.product_title}}" class="img-responsive product-image"/>
                    </div>
                    <div class="item">
                        <img src="{{item.nutrition_thumbnail}}" alt="{{item.product_title}}" class="img-responsive nutri-image"/>
                    </div>

                </div>
            </div>
            <div class="caption post-content">
                <h4 class="h_no_margin">
                    <p class="pull-left title">{{item.product_title.toLowerCase() }}</p>
                    <p class="text-right">${{item.price}}</p>
                </h4>
                <small>
                    {{item.product_desc}}
                </small>
            </div>
        </a>

    </div>

</div>

Angular 代码:

var app = angular.module('item_gallery', []);

app.controller('ItemGallery', function($http, $scope, $location) {
$http.get("/product/list")
.success(function(response) {
    $scope.item_array = response.response;
    });


});

我使用 Bower 来处理依赖关系。

{
 "name": "nutrinext",
 "version": "0.0.0",
 "dependencies": {
  "angular": "~1.3.1",
  "angular-bootstrap": "~0.11.2",
  "angular-timeago": "~0.1.3",
  "angular-ui-router": "~0.2.11",
  "ngstorage": "~0.3.0",
  "bootstrap": "~3.3.0",
  "bootstrap-markdown": "~2.7.0",
  "jquery": "1.10.2",
  "fastclick": "~1.0.3",
  "fontawesome": "~4.2.0",
  "pubnub": "~3.6.4"
 },
"devDependencies": {},
"resolutions": {
  "angular": "~1.3.1",
  "bootstrap": "~3.3.0"
 }
}

最佳答案

我有同样的问题,我缺少的是在我的 index.html 中包含 bootstrap.js,并且在添加以下内容后它起作用了。

<script type="text/javascript" src="components/bootstrap/dist/js/bootstrap.js"></script>

关于javascript - TypeError : $(. ..).carousel 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30843186/

相关文章:

javascript - 如何在 Sails.js 中为 Handlebars 配置局部和布局?

javascript - 异步设置 ReactJS 状态

Javascript 按字母顺序排序;如何将数值与数字进行比较,同时将它们与字符串进行比较?

javascript - Angular Material md-select 问题与 ng-change 和 ng-required

javascript - AngularJS 将类应用于事件的父元素?

javascript - jQuery 查询.children

javascript - 有没有一种从 asm.js 模块处理多个数组的好方法?

jquery - 从边距设置中排除一项 - 导航栏

jquery - 使用 jQuery 根据子属性将样式应用于父级?

javascript - Angular 仅在没有焦点时更新输入字段