0% found this document useful (0 votes)
45 views

Angular Model

This method returns an Observable of Comment objects by making a GET request to a JSON API, mapping the response to Comment instances, and returning the mapped data. It retrieves comment data from a URL, transforms the response into Comment objects, and returns an Observable of the Comment list.

Uploaded by

kumarcscs
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Angular Model

This method returns an Observable of Comment objects by making a GET request to a JSON API, mapping the response to Comment instances, and returning the mapped data. It retrieves comment data from a URL, transforms the response into Comment objects, and returns an Observable of the Comment list.

Uploaded by

kumarcscs
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

getAllComments(): Observable<Comment[]> {

const apiURL = 'https://jsonplaceholder.typicode.com/comments';

return this.httpClient.get<Comment[]>(apiURL, { observe: "body" }).pipe(


map((res: Comment[]) => {
return res.map((item: Comment) => {
return new Comment(
item.id,
item.postId,
item.name,
item.email,
item.body,
item.abc
);
});
})
);

export class Comment {


"id": number;
"postId": number;
"name": string;
"email": string;
"body": string;

constructor(id, postId, name, email, body) {


this.id = id;
this.postId = postId;
this.name = name;
this.email = email;
this.body = body;
}
}

You might also like