Using Other Components

Components depend on other components, directives and pipes. For example, TodoListComponent relies on TodoItemComponent. To let a component know about these dependencies we group them into a module.

  1. import {NgModule} from '@angular/core';
  2. import {TodoListComponent} from './components/todo-list.component';
  3. import {TodoItemComponent} from './components/todo-item.component';
  4. import {TodoInputComponent} from './components/todo-input.component';
  5. @NgModule({
  6. imports: [ ... ],
  7. declarations: [
  8. TodoListComponent,
  9. TodoItemComponent,
  10. TodoInputComponent
  11. ],
  12. bootstrap: [ ... ]
  13. })
  14. export class ToDoAppModule {
  15. }

The property declarations expects an array of components, directives and pipes that are part of the module.

Please see the Modules section for more info about NgModule.

原文: https://angular-2-training-book.rangle.io/handout/components/using_other_components.html