简体   繁体   中英

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. Form I refer is submitted in chrome but not in Firefox. Is nativeElement has any browser compatibility issues?

Form in 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. I tried 2, 3 different versions of firefox.

Any help is appreciated, Thanks!

you needn't a ViewChild if you want to submit a form using a button

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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