When faced with a similar situation, I encountered the limitation of not being able to access ::before or ::after HTML elements from elementRef. My workaround involved creating an additional DIV within the target HTML element that needed modification through a directive. This allowed me to change the background of the new div as if it were the ::before pseudo-element.
Here is an example of how I implemented my directive:
@Directive({selector: '[appPrimaryColor]'})
export class PrimaryColorDirective implements OnInit {
@Input() backgroundColor = false;
constructor(
private elementRef: ElementRef,
private _renderer: Renderer2,
) { }
ngOnInit() {
// Set BackgroundColor
if (this.backgroundColor) {
this._renderer.setStyle(this.elementRef.nativeElement, 'background-color', COLOR);
}
}
}
Implementation in the HTML:
<div class="icon">
<!-- step-ok-effect is the new div-->
<div
appPrimaryColor
[backgroundColor]="true"
class="step-ok-effect"></div>
<span class="icon-{{ step.state ? 'check' : step.icon }}"></span>
</div>
</div>