Is there a way to extend a component which is exported by a 3rd party library in such a way that I can intercept and change the value of a specific Input?An important mention is that the component already implements the `ngOnChanges` hook so, if I create a directive which targets the component, the directive's `ngOnChanges` hook is executed AFTER the component one.
If there is no other way to extend it and keep the original component selector, I'm OK to extend the parent component Class with a new selector, like:
@Component({
selector: 'extended-component',
template: '',
})
export class YourExtendedComponent extends ThirdPartyComponent implements OnChanges {
@Input() adjustedInputValue: string;
ngOnChanges(changes: SimpleChanges): void {
// Check if the inputValue has changed
if (changes.inputValue) {
// Your logic to adjust the input value goes here
this.adjustedInputValue = this.adjustInput(changes.inputValue.currentValue);
}
}
private adjustInput(value: string): string {
// Your custom logic to adjust the input value
return value.toUpperCase(); // Example: Convert to uppercase
}
}
The problem is that my ThirdPartyComponent has some component Providers:
@Component({
selector: 'some-component',
standalone: true,
template: '',
providers: [
SomeInjectable,
AnotherInjectable
],
encapsulation: ViewEncapsulation.None
})
Would I end up with duplicate instances for SomeInjectable?
As I said, ideally I would try to achieve this without changing the initial compoennt selector.