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?
Assuming you are inside a component you can instantiate a new pipe and apply its transformation inline like so:
let searchedItems = new SearchPipe().transform(items);
In addition, 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;
}
}
store in template:
<input hidden #searchItems="ngModel" [ngModel]="items | search" />
<!--assuming you want to reuse it inside ngFor-->
<li *ngFor="let item of searchItems.value">
{{item.Name}}
</li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With