The response of https://jsonplaceholder.typicode.com/posts is array of objects
[
{
userId: 1,
id: 1,
title: "sunt aut facere repellat",
body: "quia et suscipit suscipit recusandae consequuntur"
},
{
userId: 1,
id: 2,
title: "qui est esse",
body: "est rerum tempore vitae sequi"
},
]
so instead of pushing array of object within array, all you need to assign the response.
Create a posts interface instead of using any[] type casting
export interface IPosts = {
userId: number;
id: number;
title: string;
body: string;
}
Now fetch data from end point
posts: IPosts[]; // notice the type instead of any we have proper type.
constructor(private http:HttpClient) {
const url = 'https://jsonplaceholder.typicode.com/posts';
http.get(url).subscribe((response: IPosts[]) => this.posts = response)}
And in template just iterate the result.
<ul class="list-group" *ngIf="posts.length"> <=== for safe side you could use if condition only show if posts are available.
<li
*ngFor="let post of posts"
class="list-group-item">{{post.title}}</li>
</ul>
responsedata?[[{}, {}, ... ]]. You need to assign the array to the variable instead of pushing it:this.posts = response.