I study angular2 in the udemy course for angular2 , and the teacher wrote a directive that highlights the html element.
I try to do this as steam, but for me this is an exception _renderer.setElementStyle .
EXCEPTION: TypeError: cannot set property "background-color" of undefined to [null]
Directive:
import {Directive, ElementRef, Renderer, OnInit} from 'angular2/core'; @Directive({ selector: '[highlight-directive]' }) export class HighlightDirective implements OnInit{ private _defaultColor= 'green'; constructor(private _elmRef: ElementRef, private _renderer: Renderer) {} ngOnInit(): any { this._renderer.setElementStyle(this._elmRef, "background-color", this._defaultColor);
Tab. That I use the directive:
template: ` <div highlight-directive> Highlight me </div> <br> <div highlight-directive> 2 Highlight me 2 </div> `,
Teacher work area: 
Can someone find what I'm doing wrong?
Thanks.
source share