1

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

$("input").on('change', function() { console.log("*"); }); 
1
  • 6
    Create a directive with a selector of input and register the change event. Commented Feb 22, 2017 at 19:09

1 Answer 1

3

You can handle it using Directive as said by Igor as below

  1. create a directive using

    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') } } 
  2. Import it to the main.ts

  3. Add to declarations of the module

LIVE DEMO

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.