簡體   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