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];
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-09-01
  • 2021-07-15
  • 2021-11-07
  • 2021-11-23
相关资源
相似解决方案