Angular 2/4:如何在第一个ajax提交的回调中通过组件发布HTML表单(非ajax)?

Pra*_*tik 7 javascript angular2-forms angular angular4-forms

我想通过以旧学校方式(非Ajax)POST输入字段将表单提交到外部站点,它也提交但是Angular在跳转到外部页面之前在控制台中给出了错误.

我在HTML(模板)中使用了以下代码

<form (submit)="onSubmit($event)" method="POST"  [formGroup]="form" *ngIf='form' action="https://www.sandbox.paypal.com/cgi-bin/webscr" >
Run Code Online (Sandbox Code Playgroud)

在组件中

onSubmit(obj: any) {

    if (!this.form.valid) {
        this.helper.makeFieldsDirtyAndTouched(this.form);
    } else {
        this.loader = true;
        // save data in online_payment_ipn
        this.paymentService.saveOnlinePaymentIpn({}, 'paypal')
        .subscribe(response => {
            obj.target.submit();
        }, (err: any) => {
            this.loader = false;
            this.helper.redirectToErrorPage(err.status);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,首先这个表单通过普通的反应形式帖子(ajax)在我的网站中保存数据.现在之后我以旧的方式提交表格,像Paypal整个表格一样发布到第三方但我得到了在此输入图像描述

表单提交已取消,因为表单未连接

任何帮助表示赞赏.@HB谢谢

H.B*_*.B. 10

您可能应该使用onSubmit($event)然后取消事件到您的自定义逻辑.您可以通过访问表单event.target.传入this角度绑定可能只是不起作用,我可能会弄错.