I'm trying to follow official tutorial in Angular 2 website. This tutorial
I'm getting following error in atom IDE:
Unused label.at line 8 col 1
Cannot assign to 'Hero' because it is not a variable.at line 8 col 7
Following is my code:
import { Component } from '@angular/core';
export class Hero {
    id: number;
    name: string;
}
hero: Hero = {
  id: 1,
  name: 'Windstorm'
};
@Component({
    selector: 'my-app',
    template: `<h1>{{title}}</h1>
      <h2>{{hero.name}} details!</h2>`
})
export class AppComponent {
    title = 'Tour of Heroes';
    hero = 'Windstorm';
}
And the result:

What I have done wrong? Help is appreciated.
just keep following the tutorial and you will find the answer a bit later on the page:
export class AppComponent {
    title = 'Tour of Heroes';
    heroes = HEROES;
    selectedHero: Hero;
    onSelect(hero: Hero): void {
    this.selectedHero = hero;
}
Reference: https://angular.io/tutorial/toh-pt3
According to the tutorial you are referring to, the hero field initialization is supposed to be inside the AppComponent:
import { Component } from '@angular/core';
export class Hero {
    id: number;
    name: string;
}
@Component({
    selector: 'my-app',
    template: `<h1>{{title}}</h1>
      <h2>{{hero.name}} details!</h2>`
})
export class AppComponent {
    title = 'Tour of Heroes';
    hero: Hero = {
      id: 1,
      name: 'Windstorm'
    };
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With