What is the purpose of the @Component decorator?

Beginner

Answer

The @Component decorator is metadata that tells Angular how to process a class. It provides configuration options:

  • selector: CSS selector that identifies the component in templates
  • template/templateUrl: HTML template for the component
  • styles/styleUrls: CSS styles for the component
  • providers: Services available to the component
  • viewProviders: Services available to the component's view
  • encapsulation: View encapsulation strategy
  • changeDetection: Change detection strategy