I have multiple components; I am using Injector in the constructor for encapsulation
import { Component, Injector, OnInit } from '@angular/core';
@Component({
selector: 'app-base',
templateUrl: './base.component.html',
styleUrls: ['./base.component.css'],
})
export class BaseComponent implements OnInit {
some = '';
constructor(injector: Injector) {
this.some = injector.get(this.some);
}
ngOnInit(): void {}
}
I'm incorporating BaseComponent into another Component
import { BaseComponent } from '../base/base.component';
@Component({
selector: 'app-base-state',
templateUrl: './base-state.component.html',
styleUrls: ['./base-state.component.css'],
})
export class BaseStateComponent extends BaseComponent implements OnInit {
constructor(injector: Injector) {
super(injector);
}
ngOnInit(): void {}
}
I intend to use BaseStateComponent in other components; The question arises: Is there a way to make the injector in BaseComponent or BaseStateComponent optional? There are instances where I need a component without requiring its injector;
I am aware of the @Optional() and @Self() features
constructor(@Optional(), @Self());
However, I find it challenging to understand how these decorators work. I would appreciate if someone could explain them;