Angular 2 using ngFor with the async pipe and index

Jeremy Thomas

I would like to be able to hide rows of my table when there are more than 10 rows and I've succeeded in doing the following:

<tbody>
  <transaction-row
    *ngFor="let transaction of (transactions$ | async); let i = index;"
    [transaction]="transaction"
    [index]="i"
    [ngClass]="i >= num_hidden ? 'show' : 'hide'"
  ></transaction-row>
</tbody>

However, once I edit the transactions$ observable array by deletion or addition, all rows are shown (including the ones that were previously not shown).

Is there something else I need to do in order to get the index working asynchronously?

chrispy

Rather than hiding them, which still forces Angular to put the code in the DOM (and perform additional expensive change detection, etc), it would be better to have your observable be chained and produce the correct filtered output.

Potential example:

this.transactions$ = this.httpService.getTransactions();
this.truncatedTransctions$ = this.transactions$.map((transactions: any[]) => transactions.slice(0, 10));

Then use truncatedTransctions in your view with no ngClass.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Angular 2 - NgFor using numbers instead collections

From Java

NgFor doesn't update data with Pipe in Angular2

From Java

Using an array from Observable Object with ngFor and Async Pipe Angular 2

From Java

Angular 2 ngfor first, last, index loop

From Java

Invert Angular 2 *ngFor

From Dev

Using async pipe with ngFor

From Dev

How to import ngFor in angular 2 using Javascript?

From Dev

Cannot find a differ supporting object ,Async pipe and ngFor problems in angular2

From Dev

Angular2 ngFor skip first index

From Dev

Using pipe in *ngFor, the page sometimes updates, sometimes not

From Dev

Angular 2. Issue with *ngFor, when i use Pipe

From Dev

Angular 2 *ngFor syntax

From Dev

Angular 2 async pipe not rendering/updating Observable data automatically

From Dev

How to consume single Observable property in view from Angular2 component using async pipe?

From Dev

Angular async pipe and object property

From Dev

Angular2: *ngFor, AsyncPipe, and index

From Dev

Using date pipe in a conditional expression - Angular 2

From Dev

Error handling with Angular2 async pipe

From Dev

Safe navigation operator on an async observable and pipe in Angular 2

From Dev

Angular 2 *ngFor issue

From Dev

angular2 ngfor only if index is less than certain number

From Dev

spyOn not working with async pipe in Angular

From Dev

Angular2 async pipe with observable

From Dev

Angular2 - passing ngFor item into a pipe as a parameter?

From Dev

Write ngFor result into variable using Angular 2

From Dev

Angular2 Getting very deep nested json value using pipe! *ngFor

From Dev

Angular : Array.splice in an ngFor with a pipe

From Dev

Decrement Index of *ngFor in Angular

From Dev

*ngFor loop with async pipe and hot socket connected observable?

Related Related

  1. 1

    Angular 2 - NgFor using numbers instead collections

  2. 2

    NgFor doesn't update data with Pipe in Angular2

  3. 3

    Using an array from Observable Object with ngFor and Async Pipe Angular 2

  4. 4

    Angular 2 ngfor first, last, index loop

  5. 5

    Invert Angular 2 *ngFor

  6. 6

    Using async pipe with ngFor

  7. 7

    How to import ngFor in angular 2 using Javascript?

  8. 8

    Cannot find a differ supporting object ,Async pipe and ngFor problems in angular2

  9. 9

    Angular2 ngFor skip first index

  10. 10

    Using pipe in *ngFor, the page sometimes updates, sometimes not

  11. 11

    Angular 2. Issue with *ngFor, when i use Pipe

  12. 12

    Angular 2 *ngFor syntax

  13. 13

    Angular 2 async pipe not rendering/updating Observable data automatically

  14. 14

    How to consume single Observable property in view from Angular2 component using async pipe?

  15. 15

    Angular async pipe and object property

  16. 16

    Angular2: *ngFor, AsyncPipe, and index

  17. 17

    Using date pipe in a conditional expression - Angular 2

  18. 18

    Error handling with Angular2 async pipe

  19. 19

    Safe navigation operator on an async observable and pipe in Angular 2

  20. 20

    Angular 2 *ngFor issue

  21. 21

    angular2 ngfor only if index is less than certain number

  22. 22

    spyOn not working with async pipe in Angular

  23. 23

    Angular2 async pipe with observable

  24. 24

    Angular2 - passing ngFor item into a pipe as a parameter?

  25. 25

    Write ngFor result into variable using Angular 2

  26. 26

    Angular2 Getting very deep nested json value using pipe! *ngFor

  27. 27

    Angular : Array.splice in an ngFor with a pipe

  28. 28

    Decrement Index of *ngFor in Angular

  29. 29

    *ngFor loop with async pipe and hot socket connected observable?

HotTag

Archive