有人可以告訴我使用我的代碼發生了什麼,它不斷地說'無法編譯'。我發現別人的答案,但我的代碼看起來不錯。仍然不知道根源是什麼。謝謝。Angular Demo中的TypeScript錯誤
的代碼:
import { Component } from '@angular/core';
export class Hero {
id: number;
name: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
template: `<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>
<div><label>id: </label>{{hero.id}}</div>
<div><label>name: </label>{{hero.name}}</div>
`
})
export class AppComponent {
title = 'Tour of Heroes';
hero: Hero = {
id: 1,
name: 'Windstorm'
};
}
的錯誤消息:
ERROR in E:/workspace/angular-tour-of-heroes/src/app/app.component.ts (22,1): Unused label.
ERROR in E:/workspace/angular-tour-of-heroes/src/app/app.component.ts (22,7): Cannot assign to 'Hero' because it is not a variable.