我有以下数组:
{
"body": [{
"coursename": "introto1",
"course-lesson-name": "Welcome to One! "
}, {
"coursename": "introto2",
"course-lesson-name": "What is One?"
}, {
"coursename": "introto2",
"course-lesson-name": "What Can We do with One?"
}]
}
我正在使用以下 *ngFor 对其进行迭代:
<div>
<div class="col-sm-4" *ngFor="let product of products | keyvalue">
<a>{{ products.body[0]['coursename'] }}</a>
</div>
</div>
显然,以上内容仅锁定到第一个元素,我用什么代替元素编号(body [0])作为可迭代对象?
如果需要,这是我的组件:
export class NavigationComponent implements OnInit {
products;
constructor(private dataService: MenuserviceService) { }
ngOnInit() {
this.dataService.sendGetRequest().subscribe((data: any[])=>{
console.log(data);
this.products = data;
})
}
}