【发布时间】:2021-10-04 21:56:36
【问题描述】:
我正在我的 Angular 应用程序中集成来自 Bambora 的自定义结帐。
这是文档 - https://dev-apac.bambora.com/checkout/guides/custom-checkout/setup
我已经提供了这个 JS libaray,我已将它添加到我的 index.html 的头
<script src='https://customcheckout-uat.bambora.net.au/1.0.0/customcheckout.js'></script>
现在根据文档,我需要在<script> 标签内运行以下内容
<script>
var customCheckout = customcheckout();
var cardNumber = customCheckout.create('card-number')
cardNumber.mount('#card-number');
// ...
</script>
这是他们给出的 codepen 示例 - https://codepen.io/apac-bambora/pen/bLVXqK/
现在如何从我在本节中添加的脚本调用 customCheckout() 方法的组件的 .TS 文件中运行上述代码?
这就是我所做的。
Index.html - 添加了 JS 库
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CustomCheckout</title>
<script src='https://customcheckout-uat.bambora.net.au/1.0.0/customcheckout.js'></script>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
在我的 app.component.html 中
<div class="container">
<form id="checkout-form">
<div id="card-number"></div>
<label for="card-number" id="card-number-error"></label>
<div id="card-cvv"></div>
<label for="card-cvv" id="card-cvv-error"></label>
<div id="card-expiry"></div>
<label for="card-expiry" id="card-expiry-error"></label>
<input id="pay-button" type="submit" class="btn disabled" value="Pay" disabled="true" />
<div id="feedback"></div>
</form>
</div>
app.component.ts
import { Component, OnInit } from '@angular/core';
declare var customCheckout: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'custom-checkout';
ngOnInit() {
customCheckout = new customcheckout();
}
}
【问题讨论】:
标签: javascript angular bambora