0

I am trying to filter my list using pipe I didn't get expect out .I don't knwo how to send input field value to pipe.

here is my code

https://plnkr.co/edit/WFMo8Az7BSJaRJAVVxyE?p=preview when I type "a" it should only display "abc" in list

import { Pipe, PipeTransform } from '@angular/core';


@Pipe({ name: 'listpipe' })
export class ListPipe implements PipeTransform {
  transform(items: any[], filter: string) {
     if (!items || !filter) {
            return items;
        }
  return items.filter(item => item.name.indexOf(filter) !== -1);
  }
}

1 Answer 1

2

You forgot to pass the values string (the value of the input text) to your filter.

So in the component class, it should be :

<li *ngFor="let l of v  | listpipe:values">{{l.name}}</li>

Instead of :

<li *ngFor="let l of v  | listpipe">{{l.name}}</li>

You can find more information of the pipes parameters in the official documentation: https://angular.io/docs/ts/latest/guide/pipes.html#parameterizing-a-pipe

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.