Angular 角度演示中的TypeScript错误
有人能告诉我我的代码是怎么回事吗?它不断地说“编译失败”。我找到了其他人的答案,但我的代码看起来不错。仍然不知道根本原因是什么。谢谢 代码:Angular 角度演示中的TypeScript错误,angular,typescript,Angular,Typescript,有人能告诉我我的代码是怎么回事吗?它不断地说“编译失败”。我找到了其他人的答案,但我的代码看起来不错。仍然不知道根本原因是什么。谢谢 代码: import { Component } from '@angular/core'; export class Hero { id: number; name: string; } @Component({ selector: 'app-root', templateUrl: './app.component.html', styl
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'
};
}
我感到困惑的是,我的代码看起来不错,无法找出问题的根本原因 然后我在代码中添加了一个调试器,并尝试对其进行调试器,尽管它可能没有什么用处。但在我删除“调试器”之后,编译成功了。一切看起来又好起来了 我还是不知道这里发生了什么 我想这是npm启动的问题。(该命令以“监视模式”运行TypeScript编译器,在代码更改时自动重新编译)
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.
let hero: Hero = new Hero();
hero.id = 1;
hero. name = 'Windstorm';