繁体   English   中英

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

[英]Angular 2/4 : nativeElement.submit() does not submit form in Firefox, but works in chrome

我正在通过旧的POST方法(NON ajax)从我的页面向外部站点提交表单。 我引用的表单是使用chrome提交的,但不是使用Firefox提交的。 nativeElement是否存在浏览器兼容性问题?

以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>

我的组件

export class EsafeComponent extends GatewayBaseClass implements OnInit {

@ViewChild('gatewayFormElement') private gatewayFormElement:ElementRef;
 ...............
onSubmit(event: Event) {
    this.gatewayFormElement.nativeElement.submit();
}

以chrome形式发布到其他页面,但不在Firefox中发布。 我尝试了2、3个不同版本的Firefox。

任何帮助表示赞赏,谢谢!

如果要使用按钮提交表单,则不需要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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM