I have been stuck with the basic task, of trying to update an array and output the according values. This has been affecting the whole application.
I reduced and simplified my problem to the following. First I created the following model:
export class Recipe {
public name: string;
public description: string;
public imagePath: string;
constructor(name: string, desc: string, imagePath: string) {
this.name = name;
this.description = desc;
this.imagePath = imagePath;
}
}
I then proceeded to adding content to the recipes component:
import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
@Component({
selector: 'app-recipe-list',
templateUrl: './recipe-list.component.html',
styleUrls: ['./recipe-list.component.css']
})
export class RecipeListComponent implements OnInit {
recipes: Recipe[] = [
new Recipe('NAME', 'DESC','URL1'),
new Recipe('NAME2', 'DESC2','URL2')
];
constructor() {
}
ngOnInit() {
}
}
I then use *ngFor
in the following manner:
<a
href="#"
class="list-group-item clearfix"
*ngFor="let recipe of recipes">
<div">
<h4 class="list-group-item-heading">{{ recipe.name }}</h4>
<p class="list-group-item-text">{{ recipe.description }}</p>
</div>
<span>
<img
src="{{ recipe.imagePath }}"
alt="{{ recipe.name }}"
class="img-responsive"
style="max-height: 50px;">
</span>
</a>
I have looked at other questions such as this, however I was unable to implement solutions accordingly.
I am unable to see changes on the browser when I change my array values.
How can I add new recipes and make them visible in the browser using *ngFor
?
Any pointers on what core functionality I am missing would be appreciated.