2016-04-29 80 views
10

我在做什麼錯了?Angular 2異常:TypeError:無法讀取未定義的屬性「註釋」

app.component.ts

import {Component} from 'angular2/core'; 
@Component({ 
    selector: 'my-app', 
    template: `{{title}}` 
}) 
export class App { 
    title = "Angular 2 beta"; 
    constructor() { console.clear(); } 
} 

main.ts

import {bootstrap} from 'angular2/platform/browser'; 
import {AppComponent} from './app.component'; 

bootstrap(AppComponent); 

的錯誤是

EXCEPTION: TypeError: Cannot read property 'annotations' of undefined 

回答

19

類的名稱不匹配你是什麼引導。的,而不是

export class App { ... } 

使用

export class AppComponent { ... } 

角正試圖找到一個名爲AppComponent類的annotations財產,但該類不存在,因此誤差即。

+2

這個錯誤非常棘手。它應該簡單地說'沒有找到'應用程序'每當我在笨蛋中做一個例子時,我遇到了這個錯誤,並且花了相當長的時間來弄清楚什麼是錯誤的。 – allenhwkim

+0

不幸的是,當你使用Angular時,你會得到你所支付的。 Google似乎對提供有用的錯誤消息並不感興趣。 – sgroves

+2

我不認爲Angular開發人員不想提供有用的錯誤消息,我認爲他們只是估計了角度2的平均開發人員的理解,以及我們將如何快速計算出細節。他們只知道他們的代碼,並假設我們也是。 – TetraDev

相關問題