我正在尝试关注Angular 2网站上的官方教程。 This tutorial
我在atom IDE中遇到以下错误:
未使用的label.at第8行第1列
无法分配给'Hero',因为它不是variable.at第8行第7列
以下是我的代码:
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';
}
结果:
我做错了什么?感谢帮助。
答案 0 :(得分:20)
根据您所指的教程,android:background="drawable/you_xml_file"
字段初始化应该在AppComponent中:
hero
答案 1 :(得分:2)
继续关注本教程,稍后您会在页面上找到答案:
export class AppComponent {
title = 'Tour of Heroes';
heroes = HEROES;
selectedHero: Hero;
onSelect(hero: Hero): void {
this.selectedHero = hero;
}