管道过滤器获得调用但过滤后的值不会传回组件

时间:2017-01-01 12:16:24

标签: angular angular2-pipe

我已经为我的Drop Down创建了一个自定义管道但是过滤后的值似乎已经传递给组件,控制台中也没有错误。

我的组件 - 模板

 <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);
    }

用户数组从Web服务

填充

我的自定义管道

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 个答案:

答案 0 :(得分:1)

您缺少一个return声明:

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
       );
      }
    }
}