Add (input) to html tag dynamically in Typescript

45 views
0

I have some html that is dynamically generated – I cannot modify it directly.

In this html is an <input class="MyInputClass"> with class specified (without id) and many other atrributes. I would like to handle this input (it’s text) so that it does something (let’s say: writes itself to console) when something is written to this input.

If I had an access to this in html I would do it like this:

<input type="text" class="form-control (input)="onSearchChange($event.target.value)">

public onSearchChange(searchValue : string ) {
    console.log(searchValue);
}

Source: Angular 2 change event on every keypress

Is it possible to inject such handler?