问题
I have a legacy backend server that processes form data as request parameters. We are putting angular2 on the front end. I want to submit the angular2 form so that all fields go as request parameters so that the legacy backend doesn't have to be changed. To do this I have :
<form ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
But I also want to use the 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 does not work - angular2 complains about having #f="ngForm" when ngNoForm is declared.
Is there any way to be able to do angular2 form validations as usual, and also submit the form as regular request parameters?
回答1:
Force submit using pure JS, this worked for me:
<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>
来源:https://stackoverflow.com/questions/39772932/angular2-ngnoform-and-also-do-angular-form-validation