Home » » Angular2 Filter issue

Angular2 Filter issue

Here's how I am using the filter:
  <ion-item *ngFor="let contact of contacts | isMember">
           <ion-label>{{contact.name}}</ion-label>

           {{contact.phoneNumber}}-{{contact.isMember}}
       </ion-item>
Filter definition below:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'isMember'})
export class IsMemberPipe implements PipeTransform {
    transform(value: any): any {

        if (value.isMember === true) {
            return value;
        }
        return undefined;

    }
}
-----

Question

Goal is to only display rows that have isMember flag set to true.
------

Answers

Just ensure your pipe doesn't explode when null is passed in as value
if (value && value.isMember === true) {

0 nhận xét:

Post a Comment

Popular Posts

Powered by Blogger.