I encountered an issue with my code involving angular 13 and string[]
The error message reads: "Argument of type '(string | undefined)[]' is not assignable to parameter of type 'string[]'."
This problem occurs in my product list component.
ngOnInit(): void {
this._getPro();
this._getCate();
}
private _getPro(categoriesFilter?: string[]) {
this.proService.getProducts(categoriesFilter).subscribe((pros) => {
this.products = pros;
});
}
private _getCate() {
this.catService.getCategories().subscribe((cate) => {
this.categories = cate;
});
}
categoryFilter() {
const selectedCategories = this.categories
.filter((cate) => cate.checked)
.map((cate) => cate.id);
this._getPro(selectedCategories);
}
}
The issue also persists in my product service
//get all
getProducts(categoriesFilter?: string[]): Observable<Product[]> {
let params = new HttpParams();
if (categoriesFilter) {
params = params.append('categories', categoriesFilter.join(','));
}
return this.http.get<Product[]>(this.apiURLProducts, { params: params });
}