I am wondering why this is working:
<div *ngFor="let image of recipesList | slice:0:10">
<div>{{image.recipe_id.food_name}}</div> <!-- Outputs a list of food names -->
</div>
And why I am not able to pass this recipesList (array of objects) data into a component
<app-planning [recipeData]="recipesList"></app-planning>
Planning component:
@Component({
selector: 'app-planning',
templateUrl: './planning.component.html',
styleUrls: ['./planning.component.css']
})
export class PlanningComponent implements OnInit {
@Input() recipeData: [];
constructor() {
}
ngOnInit(): void {
console.log(this.recipeData); // Returns an empty array
}
}
recipesListvia API? If so it's empty when the component is initiated.ngOnInitis called way before the HTML-template is being rendered and its content runs. You will most likely want to usengOnChangesin order to check if the input value changed and react on it.