Encountered an error while compiling and running the code in my Angular application:
Error TS2345: Argument of type 'string | null' cannot be assigned to a parameter of type 'number'. Type 'null' is not assignable to type 'number.'
The error occurred on this line: const id = this.activateRoute.snapshot.paramMap?.get('id');
Below is the complete code snippet:
constructor(private shopService: ShopService, private activateRoute: ActivatedRoute) { }
loadProduct(){
// tslint:disable-next-line: no-non-null-assertion
const id = this.activateRoute.snapshot.paramMap?.get('id');
this.shopService.getProduct(id).subscribe(product => {
this.product = product;
}, error => {
console.log(error);
});
}
After adding any component, I encountered the following message: "Cannot GET /"