2015-11-05 39 views
0

所以我就從角以下錯誤:

rooster in rooster.uren track by $index 

但是,什麼是沒有,是創建:

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. 

所以我做了以下固定它一噸板,而我的jSon只有4條線。

的JS:

angular.module("PixelFM").controller("grootRoosterController", function ($http) { 
    var that = this; 
    that.uren = []; 
    $http({ 
     method: 'GET', 
     url: '/assets/scripts/GROOTROOSTERTEST.json' 
    }).success(function(data) { 
     that.uren = data; 
    }); 
}); 

一個重複重複的HTML:

<div class="col-md-6" ng-repeat="rooster in rooster.uren track by $index"> 
    <div class="panel panel-default"> 
     <div class="panel-body grootrooster"> 
      {{rooster.name}} 
     </div> 
    </div> 
</div> 

而對於一些奇怪的原因,這段代碼的含義是輸出萬元面板,所有留下的空...

這可能怎麼樣?謝謝。

編輯

Json;

[ 
    {"host": "Adjuh5", "showname": "", "hour": "1446674064", "cohost": "Finicky"}, 
    {"host": "Beatgrid", "showname": "", "hour": "1446674064", "cohost": ""}, 
    {"host": "Adjuh5", "showname": "", "hour": "1446674064", "cohost": ""}, 
    {"host": "Finicky", "showname": "", "hour": "1446674064", "cohost": ""} 
] 
+2

循環引用? 'ng-repeat =「公雞在rooster.uren軌道由$ index」'=>'ng-repeat =「r在rooster.uren軌道由$ index」' – Tushar

+0

包括在您的問題的答覆json –

+0

@EmirMarques我加了它 –

回答

1

適合我!檢查您的通話$ http和改變:

angular.module("PixelFM").controller("grootRoosterController", function ($http) { 
    var that = this; 
    that.uren = []; 
    $http({ 
     method: 'GET', 
     url: '/assets/scripts/GROOTROOSTERTEST.json' 
    }).success(function(data) { 
     that.uren = data; 
    }); 
}); 

要:

angular.module("PixelFM").controller("grootRoosterController", function ($scope, $http) { 
    $scope.rooster = {uren:[]; 
    $http({ 
     method: 'GET', 
     url: '/assets/scripts/GROOTROOSTERTEST.json' 
    }).success(function(data) { 
     $scope.rooster.uren = data; 
    }); 
}); 

angular.module('app', []).controller('mainCtrl', function($scope) { 
 

 
    $scope.rooster = { 
 
    uren: [{ 
 
     "host": "Adjuh5", 
 
     "showname": "", 
 
     "hour": "1446674064", 
 
     "cohost": "Finicky" 
 
    }, { 
 
     "host": "Beatgrid", 
 
     "showname": "", 
 
     "hour": "1446674064", 
 
     "cohost": "" 
 
    }, { 
 
     "host": "Adjuh5", 
 
     "showname": "", 
 
     "hour": "1446674064", 
 
     "cohost": "" 
 
    }, { 
 
     "host": "Finicky", 
 
     "showname": "", 
 
     "hour": "1446674064", 
 
     "cohost": "" 
 
    }] 
 
    }; 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app='app' ng-controller='mainCtrl'> 
 
    <hr/>Quick-Ng-Repeat 
 
    <hr/> 
 
    <div ng-repeat="rooster in rooster.uren"> 
 
    <div class="panel panel-default"> 
 
     <div class="panel-body grootrooster"> 
 
     {{rooster.host}} 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>