I'm trying to access an API that returns a JSON with some data that I then need to present in my component html by using ngFor
because it's an object. Inside the http.get
function if I console.log
the returned data, it appears fine. But when I try to present it in my view, it's not working.
Here is my component.ts:
import { HttpClient } from '@angular/common/http';
export class AnonimoComponent implements OnInit {
public medicamentos: Object;
private baseURL = 'http://website.com/api/medicamentos';
constructor(private http: HttpClient) { }
ngOnInit() {
this.getMedicamentos();
}
getMedicamentos(){
interface MedicamentoResponse {
id: number;
Name: string;
Preco: number;
}
this.http.get<MedicamentoResponse>(this.baseURL).subscribe((data) => {
this.medicamentos = data;
console.log("First:\n" + this.medicamentos);
});
}
}
Here is my html:
<ul>
<li *ngFor="let med of medicamentos$ | async">
{{med}}
</li>
</ul>
However, it's not presenting anything. Any ideas?