We have got an Angular Application with a view
<input [formControl]="fc" (keyup)="change($event)" id="test">
check if it worked: {{ fc.value }}
and the component
public fc = new FormControl('nothing here');
public change(event): void {
console.log('changed', event);
}
How can I change the input with javascript to simulate a real user input?
The solution has to work with IE11.
We can change the value with js:
const el = document.getElementById('test');
el.value = 'success';
The value changes but the change-method is not being called and the formControl.value is not being updated.
How can I achieve this?
I cannot do anything inside of the component code as its a separate environment that executes this code. I already tried with el.dispatchEvent(someEvent) after the value change. Where someEvent was new Event / new KeyboardEvent with keyup, keydown, change, and also gave it objects like {key: 's'} ... and nothing worked so far. Also tried with el.focus() and el.blur() and some other things.
The assumption is that this has to do with changeDetection and that the fc doesn't get updated since setValue nor patchValue get called.
There must be something like this:
el.value = 'success';
angular.pleaseDoCorrespondingStuff();
Any Ideas?
Please note that for simplifying the example the (keyup) is just an example here, could be anything. In reality we wrap the angular material datepicker in the template and have a (dateChange)-event here.