2017-06-21 68 views
1

我採用了棱角分明JS表NG重來顯示值顯示數據正確地角JS納克重複

這是我的代碼

<div ng-app="myapp" ng-controller="FirstCtrl"> 
    <table border="1"> 
    <tr> 
    <th ng-repeat="(key, val) in collectioninfo">{{ key }}</th> 
    </tr> 
<tr ng-repeat="row in collectioninfo"> 
     <td ng-repeat="(key, val2) in row"> 
     {{ val2 }} 
     </td> 
    </tr> 
</table> 
</div> 

var myapp = angular.module('myapp', []); 
myapp.controller('FirstCtrl', function ($scope) { 
    $scope.collectioninfo = { 
     "SDDD": "Working", 
     "RRR": "P", 
     "DateCreated": "57:52.2" 
    } 
}); 

http://jsfiddle.net/9fR23/501/

回答

3

試試這個。 collectioninfo爲對象,因此你不需要兩個嵌套ng-repeat

var myapp = angular.module('myapp', []); 
 
myapp.controller('FirstCtrl', function($scope) { 
 
    $scope.collectioninfo = { 
 
    "SDDD": "Working", 
 
    "RRR": "P", 
 
    "DateCreated": "57:52.2" 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myapp" ng-controller="FirstCtrl"> 
 
    <table border="1"> 
 
    <tr> 
 
     <th ng-repeat="(key, val) in collectioninfo">{{ key }}</th> 
 
    </tr> 
 
    <tr> 
 
     <td ng-repeat="(key, val2) in collectioninfo"> 
 
     {{ val2 }} 
 
     </td> 
 
    </tr> 
 
    </table> 
 
</div>