我正在尝试将支付网关合并到 angular 应用程序中,我发现以下付款合作伙伴提供的用于合并的 JavaScript 片段,我通过添加ngNoForm 对其进行了调整,并使其与 angular 一起使用;堆栈闪电战
<form ngNoForm method="post" action="https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp">
<input type="hidden" name="amount" value="1" >
<input type="hidden" name="currCode" value="608" >
<input type="hidden" name="payMethod" value="CC">
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
接下来不是<Form> POST + Action直接从组件模板使用 HTML ,我想对我的后端服务器进行 REST 调用,执行其他一些步骤,并将该 API 响应映射到我的支付合作伙伴期望的内容,然后使用 HttpClient POST 重定向到我的支付合作伙伴,这将应该做同样的事情并重定向到应该负责支付过程的支付合作伙伴网站,所以简而言之,我想以编程方式实现同样的事情,我尝试过:
redirectToPaymentHandler(): Observable<any> {
const urlEncodeData = 'amount=1&currCode=608&payMethod=CC';
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers = headers.append('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8');
return this.httpClient.post('https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp',
urlEncodeData, {
headers,
responseType: 'text'
}).pipe(catchError((error) => {
console.log(error)
return …Run Code Online (Sandbox Code Playgroud) 我有一台旧式后端服务器,该服务器将表单数据作为请求参数进行处理。我们将angular2放在前端。我想提交angular2表单,以便所有字段都作为请求参数,这样就不必更改旧版后端。为此,我有:
<form ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
Run Code Online (Sandbox Code Playgroud)
但我也想在Submit按钮上使用angular2表单验证:
<form #f="ngForm" ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
<button type="submit" [disabled]="!f.form.valid" class="small round">Submit</button>
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用-声明ngNoForm时,angular2抱怨有#f =“ ngForm”。
有什么方法可以像往常一样进行angular2表单验证,还可以将表单作为常规请求参数提交吗?