Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jkyoutsey/19a4849a331ae0b69b60791f15b2c9a5 to your computer and use it in GitHub Desktop.
Save jkyoutsey/19a4849a331ae0b69b60791f15b2c9a5 to your computer and use it in GitHub Desktop.
Angular Style Anchors on DOM Change Directive Step 1
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