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(, 'Windstorm'),
new Hero(, 'Bombasto'),
new Hero(, 'Magneta'),
new Hero(, 'Tornado')
];
myHero = this.heroes[];
}
上一篇:Android开发四大组件概述


下一篇:iOS开发中常用的分类方法---UIImage+Category