【问题标题】:How to call the functions of third party in AngularAngular中如何调用第三方的函数
【发布时间】:2023-02-24 20:45:44
【问题描述】:

我的应用程序中集成了一个支付网关。我正在努力保存信用卡和详细信息。所以我正在调用一个 IFrame 来加载信用卡和 ach 表格。在此表格中,有一个选项可以选择付款方式。因此,在单选按钮之间切换时,我需要在我的控制台中选择付款方式的值,文档中有一个预建函数可以做到这一点。但是,如果我在组件中定义该函数,那么它就不会被调用。

这是我指的核心 JS 代码:

<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.
}

我的角度代码:

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);
  }

【问题讨论】:

    标签: javascript angular payment-gateway


    【解决方案1】:

    因为你在 html 的脚本标签中使用它,你可以像这样使用它:

    window.ClearentSDK.init({
    ...
    ...
    

    另外,您必须在窗口的界面中添加 sdk,以便 typescript 识别它。

       declare global {
          interface Window {
            ClearentSDK?: any;
          }
       }
    

    【讨论】:

    • 我已经按照文档中的建议在 index.html 中添加了脚本。像这样 <script src="gateway-sb.clearent.net/js-sdk/js/…> 并在组件中声明 ClearentSDK。
    • 您是否也导入了它并检查了ClearentSDK 是否在角度代码中有一个实例?
    • 它没有被导入。但是,我是这样声明的: declare const ClearentSDK;它正在工作。如果它不起作用,那么即使 IFrame 也不会加载。
    • 我已经更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2021-04-08
    相关资源
    最近更新 更多