tsadkan yitbarek tsadkan yitbarek - 1 year ago 87
TypeScript Question

Angular 2 store piped value in variable

I have a pipe called search and I items I want to store the returned piped value in avariable like this (In my template)

let searchedItems = items | search

any ideas?

Answer Source

Well, assuming you are inside a component you could instantiate a new pipe and apply his transformation inline like so:

let searchedItems = new SearchPipe().transform(items);

Also, you can take advantage of Angular2's injection system:

import { SearchPipe} from './pipes';

class SearchService {

    constructor(private searchPipe: SearchPipe) {


    public searchItems(items: any[]): any[]{
        let searchedItems = this.searchPipe.transform(items);

        return searchedItems;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download