Here is a JSON format that I am working with:
[{
"id": 9156,
"slug": "chicken-seekh-wrap",
"type": "dish",
"title": "Chicken Seekh Wrap",
"cuisine_type": [2140]
},
{
"id": 9150,
"slug": "green-salad",
"type": "dish",
"title": "Green Salad",
"cuisine_type": [2141]
}]
In my Angular2 project, I have created a pipe for filtering by cuisine type:
@Pipe({
name: 'filter',
pure: false
})
export class FilterPipe implements PipeTransform {
transform(list: Array<any>, searchTerm: any): Array<any> {
if(!searchTerm) return list;
else {
return list.filter(item => item.cuisine_type[0] == searchTerm);
}
}
}
I have implemented the pipe in my view like this:
<li *ngFor="let dish of dishes | filter : 2140">
<h2>{{dish.title}}</h2>
<input type="checkbox" [formControlName]="dish.id" />
</li>
However, I encountered the following errors:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'filter' of undefined
TypeError: Cannot read property 'filter' of undefined
at FilterPipe.transform (filter.ts:20)
at checkAndUpdatePureExpressionInline (core.es5.js:11241)
at checkAndUpdateNodeInline (core.es5.js:12096)
at checkAndUpdateNode (core.es5.js:12058)
at debugCheckAndUpdateNode (core.es5.js:12687)
at debugCheckDirectivesFn (core.es5.js:12628)
at Object.View_FourthStepPage_1.currVal_0 [as updateDirectives] (FourthStepPage.html:26)
I would appreciate any help or guidance on what I might be doing wrong. Thank you.