×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jul 17, 2017 5:55 PM
Modified: Jul 17, 2017 6:06 PM
Views: 3
Tags: no tags
  1. ng g d blueColored
  2.  
  3.  
  4. import {Directive ,ElementRef, HostListener} from '@angualr/core';
  5.  
  6. @Directive({
  7.         selector: '[blueColored]'
  8. })
  9.  
  10. export class BlueColorDirective {
  11.        
  12.         constructor(element: ElementRef) {
  13.           element.nativeElement.style.color = "blue";
  14.         }
  15.  
  16.         // @HostListener   listening events on dom
  17.  
  18.  
  19.         @HostListener ('click') doSomthing() {
  20.            alert('do someting')
  21.         }
  22.    
  23.  
  24.     // ex 2.
  25.         @HostListener ('click', ['$event'])
  26.             elemClicked(elem) {
  27.                console.log('clicked', elem);
  28.             }
  29.  
  30. }
  31.  
  32.  
  33. // <h1 blueColored> </h1>