简体   繁体   English

Angular 2/4:nativeElement.submit()在Firefox中不提交表单,但在chrome中工作

[英]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.

相关问题 表单提交按钮在 Firefox 中不起作用,但在 Chrome 或 IE 中有效 - Form submit button does not work in Firefox but works in Chrome or IE Chrome上的Jquery Form.submit()可以运行但不适用于Firefox - Jquery Form.submit() on Chrome works but not in Firefox 捕获提交适用于Firefox但不适用于Chrome - Catching the Submit works in Firefox but not in Chrome 当提交按钮被隐藏时,通过按回车来提交表单; 在 Firefox 中工作,在 Chrome 中什么都不做 - Submitting a form by hitting return when the submit button is hidden; works in Firefox, does nothing in Chrome 用于在表单提交上设置 cookies 的 JS 适用于 Firefox 但不适用于 Edge/Chrome - JS for setting cookies on Form Submit works in Firefox but not Edge/Chrome [0].submit 不适用于 IE 和 Firefox,在 Chrome 中完美运行 - [0].submit not working in IE and Firefox, works perfect in Chrome Ajax提交可在Chrome / Safari中运行,但不能在Firefox / IE中运行 - Ajax submit works in Chrome/Safari but not Firefox/IE .unbind(&#39;submit&#39;)。submit()在Chrome / IE中有效,但在Firefox中无效 - .unbind('submit').submit() works in Chrome/IE but doesn't work in Firefox 提交表单在Firefox中运行正常但不适用于Safari - Submit form works fine in Firefox but not Safari 表单commit()在Firefox中不起作用,但在chrome中起作用? - Form submit() not working in firefox but is working in chrome?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM