Change directive text box - Angular2

What is the equivalent of jQuery change event on every input in Angular2? Example:

$("input").on('change', function() { console.log("*"); }); 
0
source share
1 answer

You can deal with it using the Directive, as Igor said, as shown below

  • create directive with

     import { Directive, HostListener, Renderer, ElementRef } from '@angular/core'; @Directive({ selector: '[change]' }) export class ChangeDirective{ constructor( private renderer: Renderer, private el: ElementRef ){} @HostListener('keyup') onKeyUp() { console.log('some thing key upped') } } 
  • Import it into main.ts

  • Add to module ads

Live demo

+1
source

Source: https://habr.com/ru/post/1266520/


All Articles