Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanWalker/c99a1d8ed3ded6c252dc57309cfb7ac9 to your computer and use it in GitHub Desktop.
Save NathanWalker/c99a1d8ed3ded6c252dc57309cfb7ac9 to your computer and use it in GitHub Desktop.
NativeScript for Angular Directive using @HostListener sample
import { Directive, ElementRef, HostListener, inject } from "@angular/core";
@Directive({
selector: "[appHighlight]",
})
export class HighlightDirective {
currentColor = "";
private el = inject(ElementRef);
@HostListener("tap") onTap() {
if (this.currentColor) {
this.currentColor = "";
} else {
this.currentColor = "yellow";
}
this.highlight(this.currentColor);
}
private highlight(color: string) {
this.el.nativeElement.style.backgroundColor = color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment