if (id) {
console.log(id);
this.productService.getProductById(id).subscribe(
product => this.product = product)
}
else { console.log('id is not defined') }
this.updateForm.setValue(
{
41*** productId: this.product.productId,
productName: this.product.productName,
});
If id is not defined, then you will not have set
product
, so the code starting at
41***
will obviously cause the exception. You need to change your code so the method either returns some value to indicate the problem, or throws a user defined Exception. Maybe something like:
if (id) {
console.log(id);
this.productService.getProductById(id).subscribe(
product => this.product = product)
}
else { Throw ValueError('id is not defined') }
this.updateForm.setValue(
{
41*** productId: this.product.productId,
productName: this.product.productName,
});