ngRepeat无法正常工作

时间:2016-02-04 20:10:50

标签: html angularjs json

我正在尝试将数组打印到表

这是相关代码

JS:

var d = [[
 '12:00',
 'X-Files',
 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non nisi in velit tristique scelerisque. Sed quis ipsum a nisl euismod.',
 'Mikligarður',
 '2'
]];

(我知道那些方括号太多但会有更多条目)

angular.module('angularBowerApp')
  .controller('MidCtrl',  ['$scope',
    function($scope) {
     $scope.dagskra= d;

    }
]);

HTML:

<table class="table table-responsive table-hover">
  <tr ng-repeat="a in dagskra">
    <td ng-repeat="b in a"></td>
  </tr>
</table>

但是当我运行该程序时,它不会打印任何内容

1 个答案:

答案 0 :(得分:1)

没错,你只需要使用你的b

<td ng-repeat="b in a">{{b}}</td>

&#13;
&#13;
var d = [[
 '12:00',
 'X-Files',
 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non nisi in velit tristique scelerisque. Sed quis ipsum a nisl euismod.',
 'Mikligarður',
 '2'
]];

angular.module('angularBowerApp',[])
  .controller('MidCtrl',  ['$scope',
    function($scope) {
     $scope.dagskra= d;

    }
]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table ng-app="angularBowerApp" ng-controller="MidCtrl" class="table table-responsive table-hover">
  <tr ng-repeat="a in dagskra">
    <td ng-repeat="b in a">{{b}}</td>
  </tr>
</table>
&#13;
&#13;
&#13;