Iam using Angular 11, use rxjs and i wont filter my course collection to course with category equal "frontend". but i got some error
My Code :
getPosts():Observable<ICourses[]> {
return this.http.get<ICourses[]>(`${apiURL}course/getall`).pipe(
map((courses: ICourses[]) => {
return Object.values(courses).filter(course => {
course.devCategory = "frontend"
})
})
)
}
Error :
ERROR TypeError: Cannot create property 'devCategory' on boolean 'true'
Interface ICourses :
interface ICourses {
_id: string
title: string,
image: string,
instructor: string,
topic: string,
level: string,
price: number,
hours: number,
students: number,
category: string,
devCategory: string,
created_at: Date,
updated_at: Date
date: string
}
export {ICourses}
If i use this code :
getPosts():Observable<ICourses[]> {
return this.http.get<ICourses[]>(`${apiURL}course/getall`).pipe(
map((courses: ICourses[]) => {
**return courses.filter(course => {
course.devCategory = "frontend"
})**
})
)
}
I got this error :
ERROR TypeError: courses.filter is not a function
ICoursesinterface, it looks like you did something likedevCategory: trueinstead ofdevCategory: stringcourse => course.devCategory === "frontend"the solution for your filter.courseis notICoursesbutboolean.