0

I'm using a pipe on a ngFor loop for groupBy.

<div *ngFor="let ratePlan of ratePlans | groupBy: 'fonctionnel'">

The cinematic of data retrieve is the following :

  • Retrieve ratePlans[] from @Input
  • Retrieve 'fonctionnel' key with ratePlans[i].Id

My issue is on the pipe that run once with empty key. So I need to launch the groupBy pipe when 'fonctionnel' key is set. If I set pipe as pure: false, then the groupby is working but all the next stuff is broken (every update on ratePlans[] refresh the page).

So how to resolve this problem ?

Thanks for your help.

User.Anonymous
  • 1,719
  • 1
  • 28
  • 51
  • Put a condition in your pipe that checks if fonctionnel is set ? –  Jul 11 '17 at 09:20
  • The issue is the pipe is launched only once. If it is in pure: true, then 'fonctionnel' is ever empty. I need to relaunch pipe transform when it is set. – User.Anonymous Jul 11 '17 at 09:24
  • If your pipe is only launched once, then it's useless, you'd rather make a transform function to get your groupBy. The interest of a pipe is to be launched at every model change, not only once ! –  Jul 11 '17 at 09:26
  • So why pure attribute (by default equals true) exists ? – User.Anonymous Jul 11 '17 at 09:30
  • I'm quoting from [this post](https://stackoverflow.com/questions/39285550/what-is-impure-pipe-in-angular2) : `A pure pipe is only called when Angular detects a change in the value or the parameters passed to a pipe. An impure pipe is called for every change detection cycle no matter whether the value or parameters changes.` –  Jul 11 '17 at 09:34
  • So I suppose as the pipe is binded on an Array, no change is never detected when I set the key ? So how to throw a change event on Array ? – User.Anonymous Jul 11 '17 at 09:43
  • Ok, I have resolved my issue on a different way. – User.Anonymous Jul 11 '17 at 09:54

0 Answers0