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

时间:2016-08-31 17:38:55

标签: javascript angular typescript

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

1 个答案:

答案 0 :(得分:3)

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