tsadkan yitbarek tsadkan yitbarek - 15 days ago 5x
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?


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;