Add Paypal sdk external js as an internal js file in Angular

ocean waves on seashore at daytime

I’m currently including the PayPal JS SDK in index.html with <script src="

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;

I tried saving it as paypal.js in assets/js folder and then in angular.json, I added

"scripts": [

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?

edited 1 hour ago
Preston PHX

8,6703 gold badges14 silver badges31 bronze badges

asked 2 hours ago
Prachi SharmaPrachi Sharma

1241 silver badge7 bronze badges

1 Answer

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

answered 2 hours ago
Preston PHXPreston PHX

8,6703 gold badges14 silver badges31 bronze badges

Latest posts