0
사용자 속성에 대한 클래스가 있습니다. firstName 및 lastName이 업데이트되면 'fullname'속성을 자동 채 웁니다. 그러나 지금까지, 내 코드는 컨트롤러에서 수동으로 업데이트 될 때만 채 웁니다.Typescript : getter/setter를 통해 속성 자동 채우기
'fullname'을 명시 적으로 호출하지 않고 자동 업데이트하는 방법이 있습니까? 컨트롤러
export class UserDTO {
id: number;
fullname: string;
firstName: string;
lastName: string;
private _fullname string;
get fullname(): string {
return this._fullname;
}
set fullname(value: string) {
this._fullname = this.firstName + (this.lastName ? ' ' + this.lastName : '');
} }
사용법 :
updatedUser.name = firstName + (lastName ? ' ' + lastName : '');