One question still lingers in my mind: How can I convert the JSON response from an HTTP.get request into a Typescript object instance?
Let's establish the context:
CLASS =====================
export interface IMyClass {
myClassId: number;
myClassName: string;
myClassDescription: string;
}
export class MyClass implements IMyClass {
public myClassId: number;
public myClassName: string;
public myClassDescription: string;
constructor(
myClassId: number;
myClassName: string;
myClassDescription: string;
) {
this.myClassId = myClassId
this.myClassName = myClassName
this.myClassDescription = myClassName
}
}
SERVICE===============
public getMyClassById(id: number): Observable<MyClass> {
return this.http.get<MyClass>(`${this.apiEndpoint}/myClassId?myClassID=${id}`)
}
I'm exploring ways to achieve this without utilizing the complete constructor, as my actual Model consists of approximately 12 properties. I have attempted using pipe => mapping the response as MyClass but it didn't yield the desired results.