我有這樣簡單的打字原稿類別:類和計算的屬性
customer.tsexport class Customer {
public idCustomer: number;
public Code: string;
public BusinessName: string;
public sValue: any;
public sTitle: string;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
第一3個特性(idCustomer,編碼,BUSINESSNAME)從響應的WebAPI或者由應用程序代碼增值的。
我要的是,每次這3點屬性的變化值,S值的ANS sTitle這個公式得到更新:
sValue = idCustomer
sTitle = BusinessName + ' (cod:' + Code + ')';
什麼是正確的方法來修改,以實現它的類?
更新1
現在我已經實現的get/set方法,和他們的作品,如果我實例化一個新的客戶類,並更改值
export class Customer {
//public idCustomer: number;
//public Code: string;
//public BusinessName: string;
private _idCustomer: number;
get idCustomer():number {
return this._idCustomer;
}
set idCustomer(newIdCustomer: number)
{
this._idCustomer = newIdCustomer;
this.sValue = this.idCustomer;
}
private _Code: string;
get Code(): string {
return this._Code;
}
set Code(newCode: string) {
this._Code = newCode;
this.sTitle = '(Cod:' + this._Code + ') ' + this._BusinessName;
alert();
}
private _BusinessName: string;
get BusinessName(): string {
return this._BusinessName;
}
set BusinessName(newBusinessName: string) {
this._BusinessName = newBusinessName;
this.sTitle = '(Cod:' + this._Code + ') ' + this._BusinessName;
}
public sValue: any;
public sTitle: string;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
但在這一刻是來自於價值觀WebApi映射/訂閱只傳遞3個屬性(idCustomer,Code,Business Name)sValue和sTitle沒有更新...
我認爲我也修改了構造函數,但我不知道如何去做...
感謝
使他們成爲方法或獲得者。 –
我怎樣才能讓他成爲獲得者? – DarioN1
好的,我提前了一步,我整合了問題 – DarioN1