src/app/hero.ts文件:
export class Hero {
constructor(
public id: number,
public name: string) { }
}
src/app/app.component.ts文件:
import { Component } from '@angular/core';
import { Hero } from './hero'; @Component({
selector: 'my-app',
template: `{{title}}My favorite hero is:{{myHero.name}}Heroes:{{ hero.name }}There are many heroes!`
}) export class AppComponent {
title = 'Tour of Heroes';
heroes = [
new Hero(, 'Windstorm'),
new Hero(, 'Bombasto'),
new Hero(, 'Magneta'),
new Hero(, 'Tornado')
];
myHero = this.heroes[];
}