[英]Angularjs Table Header keeps getting repeated (using ng-repeat)
標題'Speedruns'不斷重演。 我怎樣才能解決這個問題? 此外,如果有更好的方法,請告訴我。
<!DOCTYPE html> <html> <head> <link rel='stylesheet' href='styles.css'> <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="https://code.angularjs.org/1.3.0-rc.2/angular.js"></script> <script> var app = angular.module('player2', []); app.controller('MainController', function($scope, $http) { $scope.data0 = null; $scope.urls = [ // List of REST api calls with with all the streams we want. 'http://api.speedrunslive.com/test/teamK', ]; $http.get($scope.urls[0]).success(function(data) { $scope.data0 = angular.fromJson(data); console.log(angular.fromJson(data)) }); }); </script> </head> <body ng-app='player2'> <div ng-controller="MainController"> <table class="table-size" ng-repeat="chan in data0.channels"> <tr> <th class="text-center" colspan="2">Speedruns</th> </tr> <tr> <td class="text-left">{{chan.channel.display_name}}</td> <td class="text-left">{{chan.channel.current_viewers}}</td> </tr> </table> </div> </body> </html>
附上一個帶有代碼的plunker。
你要重復的是tr,所以把你的重復放在那里。 目前你正在重復整個表格。 以下應該有效:
<table class="table-size" >
<tr>
<th class="text-center" colspan="2">Speedruns</th>
</tr>
<tr ng-repeat="chan in data0.channels">
<td class="text-left">{{chan.channel.display_name}}</td>
<td class="text-left">{{chan.channel.current_viewers}}</td>
</tr>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.