I have a class for User Properties. I'm trying to auto-populate the 'fullname' property if firstName and lastName is updated. But so far, my code only populate it when it is updated manually by in the controller.
Is there a way to auto-update the 'fullname' without explicitly calling it?
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 : '');
} }
Usage in controller:
updatedUser.name = firstName + (lastName ? ' ' + lastName : '');