即使我从angular2/core导入组件,我仍然得到这种错误应该是它的源文件是不是通过npm install或我的节点下载文件需要是升级Angular2 with TypeScript:@component声明期望的编译器错误
这里是我的文件
import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';
@Component({
})
即使我从angular2/core导入组件,我仍然得到这种错误应该是它的源文件是不是通过npm install或我的节点下载文件需要是升级Angular2 with TypeScript:@component声明期望的编译器错误
这里是我的文件
import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';
@Component({
})
组件后定义一个类权。
import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';
@Component({
})
class MyClass {
}
@Component
只是一个包含该类的元数据的装饰器。换句话说,它只是以更优雅的方式为你的课堂定义了一些东西。
的@Component函数采用配置对象,并把它变成它附着到组件类定义的元数据。 Angular在运行时发现这个元数据,因此知道如何做“正确的事情”。当翻译成JavaScript(ES5)
装饰和类只是功能。装饰者必须有一个参数 - 一个函数 - 才能够装饰它。在TypeScript中,这意味着你必须把一些东西放在装饰器之后。你可以在[这篇文章]中找到更多细节(http://blog.thoughtram.io/angular/2015/05/03/the-difference-between-annotations-and-decorators.html) – Sasxa