2016-06-30 150 views
1

我是Angular2和TypeScript中的新成员。当我尝试这样的波纹管找不到名称'Component' - Angular 2 TypeScript error2304

@Component({ 
    selector: 'counter', 
    template: ` 
    {{ value }} 
    <button (click)="increase()">Increase</button> 
    <button (click)="decrease()">Decrease</button> 
    ` 
    }) 
    class Counter { 
    value: number; 

    constructor() { 
    this.value = 1; 
    } 

    increase() { 
    this.value = this.value + 1; 
    } 

    decrease() { 
    this.value = this.value - 1; 
    } 
} 

我面对一些例子“无法找到名为‘组件’”的编译错误。

有什么问题? 我该怎么办?

+3

您是否导入了组件装饰器? – toskv

回答

3

你需要在TS中导入东西,它不知道装饰者是否在其他地方,但在角度内你可以提供它。

import { Component } from '@angular/core'; 

此外请确保您导出您的课程,以便您可以将其导入其他地方。

export class Counter 
+0

这对我有效。很多。 –