Member-only story

Angular: Inheritance Without Effort

A great way of using inheritance in our app without maintenance

Kevin MATHY
Better Programming
4 min readJul 29, 2019

--

Photo by Jakub Gorajek on Unsplash

Written in TypeScript, Angular makes it possible to use the concept of inheritance in our components.

However, we face a problem when we want services in child components.

Getting Started

Let’s start by creating our BaseComponent:

See that the decorator Component is not necessary — we don’t have to declare this class in the module, as it is not a component. We can also declare it as an abstract class as we would do in regular OOP language.

Then, we create our two components extended by the BaseComponent:

When we navigate from one component to another, the logs are correctly printed in the…

--

--

Kevin MATHY
Kevin MATHY

Written by Kevin MATHY

Web developer & Angular Specialist

Responses (7)

What are your thoughts?