I am writing an angular website and I am new to the platform. I am trying to get data from a web service in JSON format then just output it. I have seen many examples where the data is first piped into an array of a class/model. But I would like to know if there is an easier way where I do not have to do this extra data structure. (This is a really simple application)
In my typescript class:
export class TestimonialsComponent implements OnInit {
public testimonials: Observable<any[]>;
baseUrl = 'http://127.0.0.1:80/';
constructor(private httpClient: HttpClient){}
ngOnInit() {
}
get_testimonials(){
this.httpClient.get(this.baseUrl).subscribe((res : any[])=>{
console.log(res);
this.testimonials = res;
});
}
And in the HTML file
<button (click)="get_testimonials()">GET /products</button>
<li *ngFor='let testimonial of testimonials | async'>
{{ testimonial.Name }}
</li>
The console successfully sees my object but I get this error message when I try to do the iteration:
ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'