在Angular中将Paypal SDK外部JS添加为内部JS文件

问题描述

我目前在带有<script src="https://www.paypal.com/sdk/js?client-id=...的index.html中包含PayPal JS SDK

要渲染按钮,请在.ts文件中跟踪以下代码

declare var paypal: any;

export class BuyComponent implements OnInit {
  @ViewChild("paypal",{ static: true }) paypalElement: ElementRef;
  paypal
      .Buttons({
        ...

我尝试将其另存为paypal.jsassets/js文件夹中,然后在angular.json添加

"scripts": [
      ...,"src/assets/js/paypal.js"
  ]

但这给了我一个ReferenceError: paypal is not defined

错误

如何在我的Angular代码中将此外部js作为内部文件包括在内?

解决方法

每页加载时,应始终由每个客户端(浏览器)从外部加载并加载paypal sdk js文件

不支持隐藏副本