One interesting feature I have implemented is a class that handles single properties and arrays of other classes:
Offert Class
import {OffertRegion} from './offert-region';
import { OffertProduct } from './offert-product';
export class Offert {
public idOffert: number;
public OffertCode: string;
public Regions: OffertRegion[];
public Products: OffertProduct[];
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
OffertRegion Class
export class OffertRegion {
public idOffert: number;
public idOffertRegion: number;
public Region: string;
public intOrder: number;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
OffertProduct Class
export class OffertProduct {
public idOffert: number;
public OffertCode: string;
public idOffertRegion: number;
public Region: string;
public intRegionOrder: number;
public idOffertRow: number;
public idProduct: number;
public ProductCode: string;
public Product: string;
public Seats: number;
public ImagePath: string;
public Qty: number;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
Encountering an issue during page loading where a compilation error in the console pops up:
offert-detail.component.ts (55,21): Property 'Products' does not exist on type 'Offert'.
The source of this error lies in the following code snippet:
s.subscribe(
res => {
console.log('header')
console.log(res.header);
console.log('regions')
console.log(res.regions);
console.log('products')
console.log(res.products);
this.offert = res.header;
this.offert.Regions = res.regions; //this is line 53
this.offert.Products = res.products; // this is line 55!!!
},
error => this.errorMessage = <any>error
);
Lines 53 and 55 appear quite similar... why would one work while the other fails?
Even when attempting to execute just these two simple lines, the error persists:
var rrr: OffertRegion[]; //OK
this.offert.Regions = rrr; //OK
var ooo: OffertProduct[]; //OK
this.offert.Products = ooo; //ERROR !!!
Any insights on how to resolve this issue would be greatly appreciated. Thanks!