I have this code:
transform(searchData: Array<vw_WebSiteCourseSearch>, searchResultContentType: string) {
if (searchData == undefined) {
return;
}
return searchData.filter((item) => item.ContentType == searchResultContentType);
}
My console prints:
ERROR TypeError: searchData.filter is not a function
at FilterCountPipe.webpackJsonp.../../../../../src/app/Common/pipes/filterCount.pipe.ts.FilterCountPipe.transform (filterCount.pipe.ts:19)
I tried to add import from rxjs/add/operator/filter, but it didn't solved it. Any ideas on how to fix it?
Thanks
The filter() method does not execute the function for empty elements.
A TypeError: "x" is not a function occurs when a function is called on an object that does not contain the called function. When calling a built-in function that expects a callback function argument, which does not exist. When the called function is within a scope that is not accessible.
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.
The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.
Should searchData
be null (or undefined), you should get an error like
TypeError: cannot read property filter of null // or undefined
Like @OscarPaz thought, filter is not a function
is thrown because the received searchData
is not an array (yet still defined and not null).
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