Skip to content

Instantly share code, notes, and snippets.

@karthikchintala1
Last active July 1, 2017 05:52
Show Gist options
  • Save karthikchintala1/36cccdd875db084aa3939c7266a051c8 to your computer and use it in GitHub Desktop.
Save karthikchintala1/36cccdd875db084aa3939c7266a051c8 to your computer and use it in GitHub Desktop.
Attribute directives in Angular 2
//Directive is imported to provide the functionality of @Directive decorator
import { Directive, ElementRef } from '@angular/core'
@Directive({ selector: '[colorMe]'})
export class ColorDirective {
//ElementRef is used to access the DOM element
constructor(private el: ElementRef) {
el.nativeElement.style.color = 'red';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment