I am new to angular 2. I was trying to change width of an element using 'ElementRef' and 'Renderer' which does not seem to work.
import { Directive, Renderer, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[myHighlight]'
})
export class myDir {
constructor(private el: ElementRef, private ren: Renderer) {
}
@HostListener('mouseenter') onMouseEnter() {
this.highlight('200');
}
@HostListener('mouseleave') onMouseLeave() {
this.highlight('30');
}
private highlight(width: string) {
this.ren.setElementStyle(this.el.nativeElement, 'width', width);
}
}