There are several ways of achieving this depending on your use case. For simplicity, you can just create a base component class with a constructor and provide the dependencies from the inheriting or subclass via the super call e.g
export class BaseComponent {
constructor(modal: ModalService) {
}
/*
Implement code and logic common to inheriting components
*/
}
You can now extend this class from your component by injecting the modal service into the child class on passing onto the base class
import {Component, OnInit} from '@angular/core';
import {BaseComponent} from './base.component';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss'],
})
export class ChildComponent extends BaseComponent implements OnInit {
constructor(modal: ModalService) {
super(modal)
}
}
You can annotate your base component with the @Component angular decorator with an empty template to make your base component life cycle aware