有没有人告诉我我的代码是怎么回事,它总是说“编译失败”。我找到了别人的答案,但我的代码看起来不错。仍然不知道根本原因是什么。谢谢。
代码:
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.发布于 2017-08-12 14:29:03
let hero: Hero = new Hero();
hero.id = 1;
hero. name = 'Windstorm';发布于 2017-08-12 16:20:13
我搞混了,我的代码看起来很好,而且找不到问题的根本原因。
然后,我将调试器添加到我的代码中,并尝试对其进行调试,尽管它可能没有用。但是在我删除“debugger”之后,编译成功了。一切看起来又好起来了。
我还是不知道这是怎么回事。
我猜是npm start的问题。(该命令在“监视模式”下运行TypeScript编译器,在代码更改时自动重新编译)。
https://stackoverflow.com/questions/45646675
复制相似问题