Forcing Zone/Digest on a pipe with static falsy

37 views Asked by At

In my angular 4 template I have a simple pipe with a boolean I toggle to check if a user has been created

<div *ngFor="let user of users | existingUser : existingUserToggleFlag">

above my data I have my ng-repeat counts like this :

<span> Total Users: {{users.length}}
<span> Existing : {(users | existingUser : true)?.length} </span>
<span> NON-Existing : {(users | existingUser : false)?.length} </span>

As you can see I pass in pipe's argument as a static falsy from the template. The template does not update though, it only update when I use the existingUserToggleFlag. I can get the length of those no problem:

<span> Existing : {(users | existingUser : existingUserToggleFlag)?.length} </span>

I'm assuming its the digest not kicking off, as I console log and it appears (first glance via console.log) that my pipe does not get triggered.

1

There are 1 answers

0
zgue On

Set users and the pipe in parentheses as shown in the FlyingHeroesPipe sample.

<div *ngFor="let user of (users | existingUser : existingUserToggleFlag)">

The interpolation in your span elements needs to be corrected to {{ .. }}

<span> Existing : {{(users | existingUser : true)?.length}} </span>
<span> NON-Existing : {{(users | existingUser : false)?.length}} </span

If this did not work, post your Pipe implementation.