The Angular 2 docs provide an example for creating an attribute directive that changes the background color of an element:
https://angular.io/docs/ts/latest/guide/attribute-directives.html
<p myHighlight>Highlight me!</p>
import { Directive, ElementRef } from '@angular/core';
@Directive({ selector: '[myHighlight]' })
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}
Can I also use el.nativeElement to get the content of the element (e.g. Highlight me!), modify this and update the element?
