0

how i can row in angular to the first

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

in the example below it added the row in the last , how i can it to be the first row not the last.

1 Answer 1

2

mate, just use unshift instead of push, then it will insert to the top of array,

  $scope.rows.unshift('Row ' + $scope.counter);
    $scope.counter++;

have done a fiddle for you:

http://codepen.io/anon/pen/QjPxvN?editors=101

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.