我有一个实现单个属性和类数组的类:

提供类

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类
export class OffertRegion {

    public idOffert: number;
    public idOffertRegion: number;
    public Region: string;
    public intOrder: number;

    constructor(values: Object = {}) {
        Object.assign(this, values);
    }
}

Offert产品类别
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);
    }
}

我不知道为什么,当我加载页面时,在控制台中出现此编译错误:

offert-detail.component.ts(55,21):属性“产品”在“Offert”类型上不存在。

产生错误的代码是这样的:
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
    );

第53行和第55行相似...为什么第一个可行而第二个不可行?

即使我只尝试这两条简单的行,也会出现错误:
var rrr: OffertRegion[];  //OK
this.offert.Regions = rrr; //OK

var ooo: OffertProduct[];  //OK
this.offert.Products = ooo; //ERROR !!!

谢谢

最佳答案

终于我解决了这个问题...

我刚刚停止了服务器并再次运行 ng服务 ...

现在可以了!

可能我把复制/粘贴/重命名文件弄得一团糟...
再见!

09-17 08:17