I am trying to build up the Tour of Heroes Application from The Angular Docs. After Defining my Array of Heroes and trying to loop through it, it only brings up empty divs.
this is my code below:
html
<h1>{{title}}</h1>
<ul class="heroes">
<li *ngFor="let hero of heroes" (click)="onSelectHero(hero)">
<span class="badge">{{hero.id}}</span>{{hero.name}}
</li>
</ul>
<div>
<h2>{{selectedHero.name}} details!</h2>
<div><label>id: </label>{{selectedHero.id}}</div>
<div>
<label>name: </label>
<input [(ngModel)]="selectedHero.name" placeholder="name"/>
</div>
</div>
typescript
import { Component } from '@angular/core';
import { Hero } from './shared/model/hero';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title:string;
heroes: Hero[];
selectedHero: Hero;
constructor(){
this.title = 'app';
this.heroes = HEROES;
}
onSelectHero(hero: Hero){
this.selectedHero = hero;
}
}
const HEROES: Hero[] = [
{
id: 11,
name: "NightOwl",
},
{
id: 12,
name: "Batman",
},
{
id: 13,
name: "Superman",
},
{
id: 14,
name: "Spiderman",
},
{
id: 15,
name: "Hulk",
}
];
Why is this is happening?