node.js - 带有 TypeScript : Declaration expected compiler error after @component 的 Angular2

标签 node.js typescript angular angular2-directives

尽管我从 angular2/core 导入了组件,但我还是收到了这种错误,它的来源应该是文件不是通过 npm install 下载的,或者我的 Node 需要升级

这是我的文件

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 只是一个包含类元数据的装饰器。换句话说,它只是以更优雅的方式为您的类定义内容。

The @Component function takes the configuration object and turns it into metadata that it attaches to the component class definition. Angular discovers this metadata at runtime and thus knows how to do "the right thing".

Read more here

关于node.js - 带有 TypeScript : Declaration expected compiler error after @component 的 Angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34824854/

相关文章:

javascript - Angular 2 应用程序转移到服务层后逻辑无法正常工作

javascript - Node.js 错误,包括 js 文件 - 找不到文件

Javascript国际象棋符号转换函数

typescript :重复的函数实现消息

node.js - 打包 nodejs C++ 共享库

javascript - Angular2 中没有服务提供者错误,为什么我需要将其注入(inject)到它的父组件中?

css - 来自 assets 的图像在 scss 中找不到

node.js - 开始使用 Promise

unit-testing - 在 Node 中模拟依赖

html - Angular - Material 表,是否可以通过单击按钮来编辑行?