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
- The hostDirectives Property
- Exposing Inputs and Outputs
- Building Reusable Behaviors
- Composition vs Inheritance