我们正在使用打字稿在Angular2中开发一个新的应用程序。有没有更简洁的方法在单独的文件中声明所有类和接口,并在angular2组件中引用它们。
import {Component, OnInit, Pipe} from 'node_modules/angular2/core';
import { HTTP_PROVIDERS, Http, Response, Headers } from 'node_modules/angular2/http';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'node_modules/angular2/router';
import { Observable } from 'node_modules/rxjs/Rx';
@Component({
selector: 'my-App',
templateUrl: '/app/Index.html',
directives: [ROUTER_DIRECTIVES, NewEvent] })
//instead of writing class here , is there any way to declare this class in a
//separate file and injecting it here.
export class Events { }
答案 0 :(得分:1)
您需要在同一模块中声明组件类,而不是在它们上应用装饰器。
@Component({ // Applied decorator
(...)
})
export class Events { // Component class
}
可以从其他模块导入装饰器和类:
import {Component} from '@angular/core'; // decorator from Angular2
import {SomeOtherClass} from './some-module'; // custom class