我在我的app.js文件中有一個數組,我希望在我的HTML表格中按順序打印<td>
行中的內容。 下面是我的app.js文件:Angular ng-repeat在HTML表格中打印數組值
(function() {
var app = angular.module('TravelI', []);
var route = [{
source : [
"San Jose",
"San Francisco",
],
destination : [
"Wellington",
"Mumbai"
],
}];
app.controller('RouteController', function ($scope) {
$scope.product = route;
$scope.addRoute = function(s, d) {
};
});
})();
HTML代碼:
<div id="DisplayTable" ng-repeat="x in product">
<table style="width: 80%" align="center">
<tr>
<th>
From
</th>
<th>
To
</th>
</tr>
<tr>
<td>{{x.source[$index]}}</td>
<td>{{x.destination[$index]}}</td>
</tr>
</table>
</div>
現在我只能看到正確的數據在陣列中的第一個元素。我想顯示器是這樣的:
From To:
San Jose Wellington
San Francisco Mumbai
我追加到兩個數組的任何城市都應該順序顯示在表格行中。
在打印只有一排,因爲你的product.length是1.您通過product.source必須循環。 –