Angular2 ngNoForm, and also do angular form validation

I have an old server that processes form data as request parameters. We put angular2 on the cutting edge. I want to submit an angular2 form so that all fields appear as query parameters, so the previous backend should not be changed. For this I have:

<form  ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">

But I also want to use angular2 form validation on the submit button:

<form #f="ngForm" ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
 <button type="submit" [disabled]="!f.form.valid" class="small round">Submit</button>

However, this will not work - angular2 complains about having # f = "ngForm" when declaring ngNoForm.

Is there a way to make the form validate angular2 as usual, and also submit the form as normal request parameters?

+2
source share
1 answer

JS, :

<form ngNoForm [formGroup]="myForm" action="http://test.local/process_post.php" target="_blank" method="POST">
    <input formControlName="alpha" name="alpha"/>
    <input formControlName="beta" name="beta"/>
    <button type="submit" [disabled]="!myForm.valid" onclick="submit()">SEND</button>
</form>
+3

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


All Articles