Pipe Filter Getting Called but the filtered value is not Passed back to component

324 Views Asked by At

I have created a Custom Pipe for my Drop Down But the filtered values dosent seem to get passed to the component there is also no error in the console .

My Component - template

 <select [(ngModel)]="userid"  (ngModelChange)="onChange()">
            <option value="">   </option>
            <option *ngFor = "let user of (users|startswith)" [value] = "user.id">
                {{user.first_name}}
            </option>
        </select>

  ngOnInit():void{
        this.appService.getUsers().then(user =>this.users = user);
    }

The users array is populated from a web service

My Custom Pipe

import { Pipe,PipeTransform } from '@angular/core'
import { Users } from './users'

@Pipe({
    name :'startswith',
})

export class PipeFilter implements PipeTransform{
    transform(value : any[]){
      if(value == null){
          return null;
      }else{

       return value.filter(item => {
            console.log(item.first_name.includes('e'));
       item.first_name.includes('e')}
       );
      }
    }

}

My Console Output which tells me the pipe is getting called

1

There are 1 best solutions below

0
On BEST ANSWER

You are missing one return statement:

export class PipeFilter implements PipeTransform{
    transform(value : any[]){
      if(value == null){
          return null;
      } else {
          return value.filter(item => {
          console.log(item.first_name.includes('e'));
          return item.first_name.includes('e')} // add return here
       );
      }
    }
}