Below there're two pieces of code. I searched a question like this but I haven't found yet. So I don't understand why in my first piece of code my function found my parameter, in this example filterId, but not in the second.
I guess it could be because filterValue is like a var declaration, What is the difference between var and let in Typescript?, instead of a block-scoped, as let. Is it ok this idea?
This is works:
getServiceAreasFiltered (page: number, filterValue: string): Observable { const filterId = filterValue; this._http.post(resource, content).pipe( flatMap(area => area.results), filter((area: ServiceAreaListItem) => area.guid === filterId), ).subscribe(x => x); }
This is not works:
getServiceAreasFiltered (page: number, filterValue?: string): Observable { this._http.post(resource, content).pipe( flatMap(area => area.results), filter((area: ServiceAreaListItem) => area.guid === filterValue), ).subscribe(x => x); }