Reputation: 49
We are developing a new App in Angular2 with typescript. Is there any cleaner way to declare all the classes and interfaces in separate files and referencing them in angular2 components .
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 { }
Upvotes: 2
Views: 1103
Reputation: 202176
You need to declare the class of components within the same module than decorators applied on them.
@Component({ // Applied decorator
(...)
})
export class Events { // Component class
}
Decorators and classes can be imported from other modules:
import {Component} from '@angular/core'; // decorator from Angular2
import {SomeOtherClass} from './some-module'; // custom class
Upvotes: 1