Eggy
Eggy

Reputation: 4174

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?

[email protected]

Upvotes: 1

Views: 52

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657691

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

Upvotes: 3

Related Questions