Angular4.0--创建类实例
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(1, 'Windstorm'), new Hero(13, 'Bombasto'), new Hero(15, 'Magneta'), new Hero(20, 'Tornado') ]; myHero = this.heroes[0]; }