2016-02-27 45 views
4

我們正在使用Bootstrap Carousel並希望加載動態幻燈片(數組中的每個項目的幻燈片)。 AngularJS用於生成數組並循環遍歷。bootstrap carousel TypeError:f [0]未定義

但是在運行時,我們得到了一個javascript錯誤TypeError: f[0] is undefined。陣列由$ http.get

填充從https://docs.angularjs.org/嘗試替代的可能性,並正在如果陣列不使用$ http.get

  • $ http.get腳本內定義的生成http://w3schools.com

    • 傳送帶陣列被適當地在 「TR NG-重複」 顯示

    這是代碼:

    <!DOCTYPE html> 
    <html> 
    <head> 
    <meta charset="ISO-8859-1"> 
    <title>Fresh</title> 
    <link rel="stylesheet" 
        href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
    <script 
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
    <script 
        src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script 
        src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
    
    </head> 
    <body> 
        <div ng-app="myApp" ng-controller="myCtrl"> 
    
         <div ng-show="names.length"> 
    
          <div id="myCarousel" class="carousel slide" data-ride="carousel"> 
           <ol class="carousel-indicators"> 
            <li data-target="#myCarousel" data-slide-to="{{ $index }}" 
             ng-repeat="x in names"></li> 
           </ol> 
    
           <div class="carousel-inner" role="listbox"> 
            <div class="item" ng-repeat="x in names">{{x.Name}} 
             {{x.Country}}</div> 
           </div> 
    
           <a class="left carousel-control" href="#myCarousel" role="button" 
            data-slide="prev"> <span 
            class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
            <span class="sr-only">Previous</span> 
           </a> <a class="right carousel-control" href="#myCarousel" role="button" 
            data-slide="next"> <span 
            class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
            <span class="sr-only">Next</span> 
           </a> 
    
          </div> 
    
         </div> 
        </div> 
    
        <script> 
    
         // window.alert('Inside script'); 
         var app = angular.module('myApp', []); 
         app.controller('myCtrl', function($scope, $http) { 
          // window.alert('Inside controller'); 
          $scope.names = []; 
          $http.get("http://www.w3schools.com/angular/customers.php").then(
            function(response) { 
             $scope.names = response.data.records; 
             window.alert('Inside get'); 
            }); 
    
         }); 
        </script> 
    </body> 
    </html> 
    
  • 回答

    4

    從DIV刪除數據騎=「旋轉木馬」

    1

    旋轉木馬內應該有一個項目這也是活躍

    我不知道如何在角度做到這一點,但這是我如何使用PHP。看看評論下面的行。

    <div class="carousel-inner" role="listbox"> 
    <?php foreach ($pages as $i => $page): ?> 
    
        // make first item active 
        <div class="item <?php if($i == 0) { echo "active"; } ?>"> 
        <img src="data:image/jpg;base64,<?php echo $page['data'] ?>" alt="..."> 
         <div class="carousel-caption"> 
          <?php echo "asdfsadfasd" ?>  
         </div> 
        </div> 
    <?php endforeach; ?> 
    </div>