Malik Kashmiri Malik Kashmiri - 2 months ago 6
TypeScript Question

Custom Search in Angular 2

Details



I am trying to implement search in angular 2 but I have no clue how to do it. I already go to different tutorials but they all not fit in my case. I have a table in which user are shown now I want to search user on Name/Email. give me some good ideas how I can do this and also some implemented solution so I will view it.

image



enter image description here

Answer

here I write a code for search pipe

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


@Pipe({
    name: "search"
})

export class SearchPipe {

    transform(value, term) {
        console.log(term + ' ' + value);
        if (term == null) {
            return null;
        }
        return value.filter((item) => item.Email.includes(term));
    }
}