[英]Angular 2/4 : nativeElement.submit() does not submit form in Firefox, but works in chrome
I am submitting form via old school POST method(NON ajax) to external site from my page. 我正在通过旧的POST方法(NON ajax)从我的页面向外部站点提交表单。 Form I refer is submitted in chrome but not in Firefox.
我引用的表单是使用chrome提交的,但不是使用Firefox提交的。 Is nativeElement has any browser compatibility issues?
nativeElement是否存在浏览器兼容性问题?
Form in html : 以html格式:
<form [formGroup]="form" #gatewayFormElement *ngIf='form' action="abcpage" (submit)="onSubmit($event)" method="POST" ngNoForm >
.........
<button [formGroup]="form" type="submit">
{{ 'Connect to Suntech' | translate }}
</button>
</form>
My component 我的组件
export class EsafeComponent extends GatewayBaseClass implements OnInit {
@ViewChild('gatewayFormElement') private gatewayFormElement:ElementRef;
...............
onSubmit(event: Event) {
this.gatewayFormElement.nativeElement.submit();
}
In chrome form is posted to other page, but not in Firefox. 以chrome形式发布到其他页面,但不在Firefox中发布。 I tried 2, 3 different versions of firefox.
我尝试了2、3个不同版本的Firefox。
Any help is appreciated, Thanks! 任何帮助表示赞赏,谢谢!
you needn't a ViewChild if you want to submit a form using a button 如果要使用按钮提交表单,则不需要ViewChild
<form #gatewayFormElement [formGroup]="form" *ngIf='form'
action="http://wwww.abcpage" method="POST">
...
<!-- not put [formGroup]="form" in the button -->
<button type="submit">
{{ 'Connect to Suntech' | translate }}
</button>
<!--you can use a button type button too-->
<button type="button" (click)="gatewayFormElement.submit()>
{{ 'Connect to Suntech' | translate }}
</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.