What is the difference between “@Component” and “@Directive” in Angular?

Technology CommunityCategory: AngularWhat is the difference between “@Component” and “@Directive” in Angular?
VietMX Staff asked 3 years ago
  • Directives add behaviour to an existing DOM element or an existing component instance.
  • A component, rather than adding/modifying behaviour, actually creates its own view (hierarchy of DOM elements) with attached behaviour.

Write a component when you want to create a reusable set of DOM elements of UI with custom behaviour. Write a directive when you want to write reusable behaviour to supplement existing DOM elements.