2017-08-12 58 views
0

有人可以告诉我使用我的代码发生了什么,它不断地说'无法编译'。我发现别人的答案,但我的代码看起来不错。仍然不知道根源是什么。谢谢。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. 

回答

1
let hero: Hero = new Hero(); 
hero.id = 1; 
hero. name = 'Windstorm'; 
0

我迷惑,我的代码看起来不错,并不能找出问题的根源。

然后我在我的代码中添加一个调试器并尝试调试它,尽管它可能没用。但是在我删除'调试器'后,编译成功。而且一切看起来都很好。

我还不知道这里发生了什么。

我想这是npm start问题。 (该命令以“监视模式”运行TypeScript编译器,在代码更改时自动重新编译)。