I have created a basic class structure
export class SampleObj{
item1: string;
item2: string;
item3: string;
}
I am fetching data from the backend and populating this class using HttpClient
:
this.httpClient.get<SampleObj[]>(`backendUrl`).subscribe(
(response: SampleObj[]) => {
//...additional code...
}
);
Now, I want to add a new property item4
in this class that will be initialized based on other properties during instantiation and should be accessible in the returned response
. I attempted to modify the class definition as shown below but encountered an issue. How can I achieve my desired outcome?
export class SampleObj{
item1: string;
item2: string;
item3: string;
item4: string;
constructor(item1, item2, item3) {
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
this.item4 = item1 + item2 + item3;
}
}