Code snippet from shop.service.ts
getProducts(brandId?: number, typeId?: number) {
let params = new HttpParams();
if (brandId){
params = params.append('brandId', brandId.toString());
}
if (typeId){
params = params.append('typeId', typeId.toString());
}
return this.http.get<IPagination>(this.baseUrl + 'products', {observe: 'response', params})
.pipe(
map(response => {
return response.body;
})
);
}
This is the code snippet from shop.component.ts:
getProducts(){
this.shopService.getProducts(this.brandIdSelected, this.typeIdSelected).subscribe(response => {
this.products = response.data;
}, error => {
console.log(error);
});
}
I need some guidance on why response.data is triggering an error in shop.component.ts?
Note: The error message says "Object is possibly 'null' : ts(2531)".