0Pricing
Angular Academy · Lesson

Composition vs Inheritance

Prefer composition for shared behavior.

Two Reuse Strategies

To share behavior between components you can use inheritance (extend a base class) or composition (combine smaller pieces). Angular's composition API makes composition the preferred default.

Inheritance Recap

With inheritance, a component extends a base component or directive and reuses its inputs, outputs, and logic.

export class FancyButton extends BaseButton {
  // inherits BaseButton members
}

All lessons in this course

  1. The hostDirectives Property
  2. Exposing Inputs and Outputs
  3. Building Reusable Behaviors
  4. Composition vs Inheritance
← Back to Angular Academy