我使用的firsst時間的角度,我建立一個API的服務來獲得JSON數組對象從laravel後端數據:* ngfor angular2整合laravel
getFoodsByCat(id :number): Observable<any> {
return this.http.get('http://livrer/api/menu/' +id)
.map(
(response: Response) => { return response.json().foods;
}
);}
在我的部分我用的是這種服務即:
export class FoodsComponent implements OnInit {
@Input() food : Food ;
foods: Food[];
constructor(private foodService: FoodService) { }
ngOnInit() {
onGetFoodsByCategorie(id){
this.foodService.getFoodsByCat(id)
.subscribe(
(foods: Food[])=> this.foods = foods,
(error : Response)=> console.log(error)
);
} }
但在模板我用
<ul class="resp-tabs-list">
<li class="resp-tab-item" (click)="onGetFoodsByCategorie(1)">Panninis</li>
<li class="resp-tab-item" (click)="onGetFoodsByCategorie(2)">Tajines</li>
<li class="resp-tab-item" (click)="onGetFoodsByCategorie(3)">Sandwichs</li>
<li class="resp-tab-item" (click)="onGetFoodsByCategorie(4)">Pizzas</li>
</ul>
<li *ngFor= "let food of foods" [food]="foods">
//some style and data
</li>
我得到這個錯誤:
Error: Template parse errors:
Can't bind to 'food' since it isn't a known property of 'li'. ("
<li *ngFor= "let food of foods" [ERROR ->][food]="foods">
<div class="item">
<div class="thumbnail-menu-modern">
"): [email protected]:32