Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Dec 12, 2017 12:42 PM
Views: 20
Tags: no tags
  1. import {Directive, HostListener} from '@angular/core';
  2.  
  3. @Directive({
  4.   selector: '[appConfirm]'
  5. })
  6. export class ConfirmDirective {
  7.   @HostListener('click', ['$event'])
  8.   confirmFirst(event: Event) {
  9.     const confirmed = window.confirm('Are you sure you want to do this?');
  10.    
  11.     console.log('confirmed as', confirmed);
  12.    
  13.     return confirmed;
  14.   }
  15. }
  16.  
  17.  
  18. ========================
  19. How to use in component
  20. ========================
  21. <input type="text" appConfirm>
  22.