Search code examples
javascriptangularpaypalpaypal-sandbox

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

To render the buttons, in the .ts file, I'm following up with this code:

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

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

but this gives me error as ReferenceError: paypal is not defined

How can I include this external js as internal file in my Angular code?


Solution

  • The paypal sdk js file should always be sourced and loaded externally by each client (browser) on page load

    There is no support for a stashed copy