john
john

Reputation: 58

Display from first row of array lists in angular

I have an array of lists which is getting from the db. It is displayed as row in the console. That is from row[0] to row[10]. What i want is i need to hide the row[0] and display the remaining row[1] to row[10]. Only need is hide the first list/row. i am using angular 8 . How to do this?

Upvotes: 0

Views: 3651

Answers (2)

Gaurang Dhorda
Gaurang Dhorda

Reputation: 3387

Working Demo For Use-case One in this StackBlitz link

Working Demo For Use-case Two in this StackBlitz Link

1. If you want to filter record in component file then..

     this.arrays = this.arrays.filter((value, i) => i !== 0);

By filtering you can remove first row[0] and only display rest record of objects only.

Template is

<div *ngFor="let row of arrays; let i = index">
   <ng-container>
     {{row | json}}
   </ng-container>
</div>

2. If you want to filter intemplate then below code is working for you..

template.html is

<div *ngFor="let row of arrays; let i = index">
   <ng-container *ngIf=" i !== 0 " >
      {{row | json}}
   </ng-container>
</div>

component.ts file is

arrays = [{
  id: 1,
  name: 'Row 1'
},
{  
  id: 2,
  name: 'Row 2'
},{
  id: 3,
  name: 'Row 3'
},{
  id: 4,
  name: 'Row 5'
}]

Upvotes: 1

Arun Mohan
Arun Mohan

Reputation: 1227

<div *ngFor="let row of array; let first = first">
<ng-container *ngIf="!first" >
  {{row}}
</ng-container>
</div>

Using first will make code more readable. (Check documentation for more in ngFor)

Upvotes: 1

Related Questions