0

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?

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
olayemii
  • 590
  • 1
  • 3
  • 16
  • ok, same thing..i just found out that clicking on any of the empty divs brings back all the text in the divs? – olayemii Jul 19 '17 at 02:07