Eggy Eggy - 3 months ago 10
TypeScript Question

What is the difference between passing component to declarations or to directives?

Let's say I have usual component

MyComponent
. To use it, should I pass it to
declarations
array in my main module or
directives
array in main component?

// 1)
@NgModule({
declarations: [
AppComponent,
MyComponent
],
imports: [],
providers: [],
bootstrap: [AppComponent]
})

// 2)
@Component({
selector: 'app-root',
directives: [MyComponent]
})
export class AppComponent { }


What if the component is deep into application tree, could I use it anywhere in main module, if passed to
declarations
array?

angular@2.0.0-rc.5

Answer

directives and pipes in @Component() and @Directive() are deprecated. declarations is the new RC.5/NgModules way.