Skip to content

Instantly share code, notes, and snippets.

@isaurssaurav
Last active March 22, 2017 17:25
Show Gist options
  • Select an option

  • Save isaurssaurav/bb3ee7ce5619fcd671c3df9f1366cf4b to your computer and use it in GitHub Desktop.

Select an option

Save isaurssaurav/bb3ee7ce5619fcd671c3df9f1366cf4b to your computer and use it in GitHub Desktop.
angular2.HostBinding and HostListener example
import { Directive ,HostListener,HostBinding } from '@angular/core';
@Directive({
selector: '[highlight]', //element having hightlight [attribute] is selected or .class or #id or component
})
export class HighlightDirective {
@HostListener('mouseenter') mouseover(){
this.backgroundColor = 'green';
//can use renderer here to change style here
}
@HostListener('mouseleave') mouseleave(){
this.backgroundColor = 'white';
}
@HostBinding('style.backgroundColor') get setColor(){
return this.backgroundColor;
} //read only ..
private backgroundColor = 'white';
constructor() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment