I am trying to display my json array in html using *ngFor but I believe it's not working because it needs to be inside the class AppComponent. But if I try to move the source code to make the json object inside the AppComponent class I get an error.
This is my app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
s = ['Windstorm', 'Bombasto', 'Magneta', 'Tornado'];
myHero = this.s[0];
}
interface Person {
name: string;
year: number;
}
var people: Person[] = [{ name: 'robert', year: 1993 }];
var newPerson: Person = { name: 'joe', year: 1992 };
people.push(newPerson);
newPerson = {name: 'jose', year: 1997};
people.push(newPerson);
console.log(people[2].name);
This is my app.component.html file
<p>HEllo</p>
<ul>
<li *ngFor="let name of s">
{{ name }}
</li>
</ul>
I want to do something to what I did in the html file but with the other array
erroryou encountered.