英文:
How to call the functions of third party in Angular
问题
这是您要翻译的内容:
I have a payment gateway integrated into my application. I am working on saving credit card and ach details. So I am calling an IFrame to load the credit card and ach forms. In this form there is an option to select the mode of payment. So while switching between the radio buttons I need the values of selected payment method in my console, there is a prebuilt function to do so in the doc. But if I define that function in the component then it is not getting called.
This is the core JS code I am referring to:
<script type="text/javascript">
ClearentSDK.init({
"baseUrl": "https://gateway-sb.clearent.net",
"pk": "YOUR PUBLIC KEY GOES HERE",
"enableAch":true
});
function ClearentOnPaymentTypeChange(paymentType) {
console.log("Payment type was changed to ", paymentType) // this is the function to log which payment type is selected.
}
My Angular code:
setClearentToken() {
this.isLoadingResults = false;
ClearentSDK.init({
"baseUrl": "https://gateway-sb.clearent.net",
"pk": "Your Public Key", //I am providing the actual public key here. Just removed due the security.
"enableAch": true
});
}
ClearentOnPaymentTypeChange(paymentType) {
console.log("Payment type was changed to ", paymentType);
}
英文:
I have a payment gateway integrated into my application. I am working on saving credit card and ach details. So I am calling an IFrame to load the credit card and ach forms. In this form there is an option to select the mode of payment. So while switching between the radio buttons I need the values of selected payment method in my console, there is a prebuilt function to do so in the doc. But if I define that function in the component then it is not getting called.
This is the core JS code I am referring to:
<script type="text/javascript">
ClearentSDK.init({
"baseUrl": "https://gateway-sb.clearent.net",
"pk": "YOUR PUBLIC KEY GOES HERE",
"enableAch":true
});
function ClearentOnPaymentTypeChange(paymentType) {
console.log("Payment type was changed to ", paymentType) // this is the function to log which payment type is selected.
}
My Angular code:
setClearentToken() {
this.isLoadingResults = false;
ClearentSDK.init({
"baseUrl": "https://gateway-sb.clearent.net",
"pk": "Your Public Key", //I am providing the actual public key here. Just removed due the security.
"enableAch": true
});
}
ClearentOnPaymentTypeChange(paymentType) {
console.log("Payment type was changed to ", paymentType);
}
答案1
得分: 1
窗口标签的HTML中使用时,可以这样使用:
window.ClearentSDK.init({
// ...
// ...
});
此外,您需要将SDK添加到TypeScript中窗口的接口以便识别它:
declare global {
interface Window {
ClearentSDK?: any;
}
}
英文:
since you are using it in the script tag in html, you can use it like this:
window.ClearentSDK.init({
...
...
also, you'll have to add the sdk in the window's interface for typescript to identify it.
declare global {
interface Window {
ClearentSDK?: any;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论