Categories: AngularJS

AngularJS Tables

Share

In AngularJS Tables we can show repeatable data. Using ng-repeat directive we can draw table easily. See the below example how to use ng-repeat in table.

Table data is normally repeatable by default and ng-repeat directive can be used perfectly to create table easily.

Example of AngularJS Tables:

<table>
   <tr>
      <th>Name</th>
      <th>Age</th>
   </tr>
   <tr ng-repeat="x in user">
      <td>{{ x.name }}</td>
      <td>{{ x.age }}</td>
   </tr>
</table>

Read Also: HTML DOM – AngularJS

OutPut:

Name Age
John Doe 25
Jane Doe 21
Robert Stuart 35

To sort the table, add an orderBy filter:

<tr ng-repeat="x in user | orderBy : 'name'">
 <td>{{ x.name }}</td>
 <td>{{ x.age }}</td>
</tr>

In order to display the table index, use <td> with $index:

<tr ng-repeat="x in user">
<td>{{ $index + 1 }}</td>
<td>{{ x.name }}</td> 
<td>{{ x.age }}</td> 
</tr>

For example:

No. Name Age
1 John Doe 25
2 Jane Doe 21
3 Robert Stuart 35

View Comments

  • Makes sense. I just wanted to throw it out there in case there was some part I didn't understand. Thanks.

Recent Posts

Optimize Your Hormonal Balance: Enclomiphene Citrate for Enhanced Wellness

Hormonal balance plays a pivotal role in overall well-being, influencing various aspects of health, from…

8 hours ago

Paul Kanes Explores the World of Canine Companionship through Dog Walking

Dog walking is an excellent way to maintain your furry friend's camaraderie and provides many…

11 hours ago

Top 5 Must-Have Features Every Mobile App Needs to Succeed

Introduction Businesses understand the diverse requirements of mobile applications, which provide a competitive advantage. There…

16 hours ago

IoT Data Analytics: Ways to Gain Value from IoT Data

The Internet of Things (IoT) has recently changed the world. It links gadgets together and…

16 hours ago

The Rise of NFTs: Exploring the Impact of Non-Fungible Tokens on the Digital Economy

NFTs, or Non-Fungible Tokens, are revolutionizing the digital economy. These unique digital assets, authenticated through…

1 day ago

What to Ask Before You Hand Your Laptop For Repairing

It is safe to say that if you are in need of a good laptop…

2 days ago