2017-04-20 70 views
1

我需要提交來自支付網關的表單。我們的後端人員要求我將innerHtml並在渲染後發送。我得到它在鉻上工作,但在Firefox上失敗。現在我試圖在我們的測試環境中修復它,後端添加了JSON返回所需的所有屬性,以複製他發送給我的表單,以便我可以製作自己的表單。但仍未能在Firefox上提交。angular2在打字稿中提交表單

有人有相同的經歷嗎?請給我點光。

是否有我需要知道的任何Firefox特定修復程序?

下面是Chrome和Safari

import { Component, OnInit, AfterViewInit, ViewChild, ElementRef,DoCheck, ViewChildren, QueryList } from '@angular/core'; 
import { BrowserModule, DomSanitizer, SafeResourceUrl, SafeUrl} from '@angular/platform-browser'; 
import { PaymentService } from '../../_services/payment.service'; 
import { Loader } from '../../_services/loader.service'; 

@Component({ 
    selector: 'bdf-payment-form', 
    templateUrl: './payment-form.component.html', 
    styleUrls: ['./payment-form.component.scss'] 
}) 
export class PaymentFormComponent implements OnInit,DoCheck, AfterViewInit { 

    form : SafeResourceUrl; 
    // @ViewChild('paymentFormContainer') container: ElementRef; 
    @ViewChild('paymentForm') myForm: ElementRef; 
    loader; 
    constructor(private paymentService:PaymentService, 
    private sanitizer: DomSanitizer, 
    private loaderService: Loader, 
    private elRef:ElementRef) { } 

    ngDoCheck(){ 

    } 
    ngOnInit() { 
    console.log(this.paymentService.paymentForm); 
    this.paymentService.paymentForm ? this.form = this.sanitizer.bypassSecurityTrustHtml(this.paymentService.paymentForm) : null 
    this.loader = true; 
    } 

    ngAfterViewInit() { 
    let test; 
    if(this.form){ 
     test = this.elRef.nativeElement.querySelector('form') 
     console.log(test) 
     test.submit(); 
    } 

    } 

} 

回答

0

你不應該使用submit()方法,以避免刷新頁面重定向的工作代碼。

http服務用於將表單數據序列化爲表單提交給json。如果您將表單元素綁定到模型,那麼將模型發回到後端會更容易。

+0

但是我可以做到這一點。後端人說,我們需要通過html形式發送它,因爲瀏覽器需要通過url。當瀏覽器訪問帶有字段和值的url時。它將進入OTP(一次性密碼)頁面,然後回調將觸發並重定向回到我們的確認頁面。 有沒有更好的方法來做到這一點? 感謝@Roman的回覆。 – Don