Angular2 ngNoForm并也进行角度形式验证 [英] Angular2 ngNoForm and also do angular form validation
问题描述
我有一个旧式后端服务器,该服务器将表单数据作为请求参数进行处理. 我们将angular2放在前端.我想提交angular2表单,以便所有字段都作为请求参数,这样就不必更改旧版后端. 为此,我有:
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">
但是我也想在提交"按钮上使用angular2表单验证:
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>
但是这不起作用-声明ngNoForm时,angular2抱怨拥有#f ="ngForm".
However this does not work - angular2 complains about having #f="ngForm" when ngNoForm is declared.
有什么方法可以像往常一样进行angular2表单验证,也可以将表单作为常规请求参数提交?
Is there any way to be able to do angular2 form validations as usual, and also submit the form as regular request parameters?
推荐答案
强制使用纯JS提交,这对我有用:
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>
这篇关于Angular2 ngNoForm并也进行角度形式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!