I'm trying to take a response and display the array on the page. There are no errors, but there also no list on the page.
My list is: {"id":4,"content":"Hello, World! "}
Here is my greeting-list.component.ts:
import { Component, OnInit } from '@angular/core';
import { GreetingService } from '../shared/greeting/greeting.service';
import { map } from "rxjs/operators";
@Component({
selector: 'app-greeting-list',
templateUrl: './greeting-list.component.html',
styleUrls: ['./greeting-list.component.css']
})
export class GreetingListComponent implements OnInit {
greetings: Array<any>;
constructor(private greetingService: GreetingService) { }
ngOnInit(): void {
//this.greetingService.getAll().subscribe(data => {
// this.greetings = data;
//});
this.greetingService.getAll().pipe(map(data => {
this.greetings = [data];
}));
}
}
I originally had:
//this.greetingService.getAll().subscribe(data => {
// this.greetings = data;
//});
but I was getting an error Angular: 'Cannot find a differ supporting object '[object Object]' of type 'object' so I changed it to the code below it.
Here is my greeting-list.component.html:
<div *ngFor="let greeting of greetings">
{{greeting.name}}
</div>
{"id":4,"content":"Hello, World! "}this is not a list that's why you can not use it in ngFor{id:.., content:..}, there is nonamefield in itnameproperty it shouldn't give above error. So it looks like the response is not in array form.