Skip to content

Instantly share code, notes, and snippets.

@rajaramtt
Created February 18, 2019 18:11
Show Gist options
  • Save rajaramtt/8eedc5fa8416e80742bd5a28c7141bf2 to your computer and use it in GitHub Desktop.
Save rajaramtt/8eedc5fa8416e80742bd5a28c7141bf2 to your computer and use it in GitHub Desktop.
<!-- attention, we have the c_highlight class -->
<!-- c_highlight is the selector property value of the directive -->
<p class="c_highlight">
Some text.
</p>
import {Component,HostListener,Directive,HostBinding} from '@angular/core';
@Directive({
// this directive will work only if the DOM el has the c_highlight class
selector: '.c_highlight'
})
export class HostDirective {
// we could pass lots of thing to the HostBinding function.
// like class.valid or attr.required etc.
@HostBinding('style.backgroundColor') c_colorrr = "red";
@HostListener('mouseenter') c_onEnterrr() {
this.c_colorrr= "blue" ;
}
@HostListener('mouseleave') c_onLeaveee() {
this.c_colorrr = "yellow" ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment