I am currently working on a simple application using Ionic (angular) and I am facing an issue with the error message:
Cannot set property 'origin' of undefined
Below is the interface for Product.ts:
export interface Products{
id: number;
new: boolean;
origin: string;
branch: string;
product: string;
quantity: string;
productId: string;
Detail_product: string;
Installed: boolean;
}
Here is the relevant TypeScript code:
ngOnInit() {
this.makeObject("03-2-450-2");
}
makeObject(qrcode) {
let obj: Products ;
let Qrstring: string = qrcode;
obj.origin! = Qrstring.substring(0, Qrstring.indexOf("-"));
console.log(obj.origin);
}
}