我怎样才能在第一个角度排成一行
html:
<title>Add Rows</title>
<link href="http://cdn.foundation5.zurb.com/foundation.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
</head>
<body ng-controller="MainController">
<a href="#" class="button" ng-click="addRow()">Add Row {{counter}}</a>
<table>
<thead>
<tr>
<th width="200">Some Header</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="rowContent in rows">
<td>{{rowContent}}</td>
</tr>
</tbody>
</table>
</body>
</html>
js:
angular.module('MyApp', [])
.controller('MainController', [ '$scope', function($scope) {
$scope.rows = ['Row 1', 'Row 2'];
$scope.counter = 3;
$scope.addRow = function() {
$scope.rows.push('Row ' + $scope.counter);
$scope.counter++;
}
}]);
http://codepen.io/calendee/pen/buCHf
在下面的示例中 它在最后添加了一行,我怎么能成为第一行而不是最后一行。
答案 0 :(得分:2)
配合,只需使用unshift而不是push,然后它将插入到数组的顶部,
$scope.rows.unshift('Row ' + $scope.counter);
$scope.counter++;
为你做了一个小提琴: