简体   繁体   English

在Angular中添加Paypal sdk外部js作为内部js文件

[英]Add Paypal sdk external js as an internal js file in Angular

I'm currently including the PayPal JS SDK in index.html with <script src="https://www.paypal.com/sdk/js?client-id=...我目前正在 index.html 中使用<script src="https://www.paypal.com/sdk/js?client-id=...

To render the buttons, in the .ts file, I'm following up with this code:为了呈现按钮,在 .ts 文件中,我正在跟进以下代码:

declare var paypal: any;

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

I tried saving it as paypal.js in assets/js folder and then in angular.json , I added我试图将其保存为paypal.jsassets/js文件夹,然后在angular.json ,我加

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

but this gives me error as ReferenceError: paypal is not defined但这给了我一个错误,因为ReferenceError: paypal is not defined

How can I include this external js as internal file in my Angular code?如何将此外部 js 作为内部文件包含在我的 Angular 代码中?

The paypal sdk js file should always be sourced and loaded externally by each client (browser) on page load paypal sdk js 文件应始终由每个客户端(浏览器)在页面加载时从外部获取和加载

There is no support for a stashed copy不支持隐藏副本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM