大家好,有人能帮我把包含products对象的JSON放到角HTML中吗?我让它在控制台中工作(见下图),但我不知道如何用HTML显示产品数据。这就是我做的代码。
我的app.component.html是
`<div *ngFor="let product of data.products" style="text-align:center">
<div>
{{ product.id }}
{{ product.product_name }}
</div>` 我的app.component.ts是
export class AppComponent {
title = 'Isham-ColdBanana';
public data:any = []
constructor(private http: HttpClient) {
}
getData(){
const url ='https://my-json-server.typicode.com/TomSearle/cb-devtest-api/db'
this.http.get(url).subscribe((res)=>{
this.data = res
console.log(this.data)
})
}
ngOnInit(){
this.getData();
}
}

发布于 2022-09-15 11:45:55
知道了,我把app.component.ts修改成了public data:any = {locations:[], products:[]}
https://stackoverflow.com/questions/73723127
复制相似问题