Created
February 18, 2019 18:11
-
-
Save rajaramtt/8eedc5fa8416e80742bd5a28c7141bf2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- attention, we have the c_highlight class --> | |
<!-- c_highlight is the selector property value of the directive --> | |
<p class="c_highlight"> | |
Some text. | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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