Created
February 9, 2022 20:50
-
-
Save jkyoutsey/19a4849a331ae0b69b60791f15b2c9a5 to your computer and use it in GitHub Desktop.
Angular Style Anchors on DOM Change Directive Step 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AfterViewInit, Directive, ElementRef, Renderer2 } from '@angular/core'; | |
@Directive({ | |
selector: '[myStyleAnchors]' | |
}) | |
export class StyleAnchorsDirective implements AfterViewInit { | |
constructor(private el: ElementRef, private renderer: Renderer2) {} | |
ngAfterViewInit(): void { | |
this.styleAnchors(); | |
} | |
private styleAnchors() { | |
const anchors = this.el.nativeElement.querySelectorAll('a'); | |
anchors.forEach(a => this.renderer.addClass(a, 'my-cool-class')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment