0

I have the following array data,,I want to use Angularjs ng-repeat to put this data in table like the following image, Can anyone help please?

      var data=[
              {status:"open",year:2014,value:100.00},
              {status:"open",year:2015,value:200.00},
              {status:"open",year:2016,value:300.00},
              {status:"approved",year:2016,value:10.00},
              {status:"approved",year:2015,value:20.00},
              {status:"approved",year:2016,value:30.00},
              {status:"closed",year:2016,value:1.00},
              {status:"closed",year:2014,value:3.00},
              {status:"closed",year:2013,value:-10.00}
              ]

enter image description here

1

2 Answers 2

1

Here is Working Example with ng-repeat and array data...

// Code goes here
var app = angular.module('soApp', []);

app.controller('DemoController', ['$scope', function($scope) {
  $scope.data = [
    {status:"open",year:2014,value:100.00},
    {status:"open",year:2015,value:200.00},
    {status:"open",year:2016,value:300.00},
    {status:"approved",year:2016,value:10.00},
    {status:"approved",year:2015,value:20.00},
    {status:"approved",year:2016,value:30.00},
    {status:"closed",year:2016,value:1.00},
    {status:"closed",year:2014,value:3.00},
    {status:"closed",year:2013,value:-10.00}
  ];
}])
table{border:1px solid #ccc; font-size:12px; width:100%;     border-collapse: collapse;}
table td, table th{border:1px solid #ccc; padding:5px;}
 <!DOCTYPE html>
<html ng-app="soApp">

  <head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <style type="text/css">
      body{font-family:'helvetica', 'arial', sans-serif;}
      td,th{padding:0 10px;text-align:left;}
    </style>
  </head>

  <body ng-controller="DemoController">
    <table>
      <thead>
        <tr>
          <th>Status</th>
          <th>Year</th>
          <th>Value</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in data">
          <td ng-bind="row.status"></td>
          <td ng-bind="row.year"></td>
          <td ng-bind="row.value"></td>
        </tr>
      </tbody>
    </table>
  </body>

</html>

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

Comments

0

Welcome to Angular! You'll be using this pattern a lot:

  1. Attach data to $scope in your controller
  2. Add the ng-repeat="row in data" attribute to a tr element
  3. Use ng-bind="row.status on the td elements

Plunkr

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.