For automated testing, I would like to fill angular 4 forms. But after submission, Angular is not aware of the changes.
I have forms using form builder with formgroup and formcontrol.
Outside the application, I need to do some automated testing. So when I try to fill the form $('#firstName').val('John');
and submit the form : Angular gives me the previous value in the form and doesn't detect changes on it.
I tried multiple solution, but nothing works like
- Run change detection on form submission
this.form.updateValueAndValidity()
- playing with
ngZone
- playing with Change events
I have no idea how I can force Angular to detect my change on the form.
UPDATE HTML
<input type="text" class="input-event" name="firstName" id="firstName" placeholder="First Name" [formControlName]="formFieldNames.firstName" />
UPDATE 2
Here's an example : https://run.plnkr.co/sqseg6kObDICjdEa/
If you fill the form with some data, and submit, you will get the right data in the console.
Now, if you put in the console document.getElementById('fullname').value = 'Jean';
And re-submit, you will see that angular did not update the data, and I would like to know how can I make it so.