Load Script into TypeScript file?

I am trying to add the following script tag to my Angular 2 project, however I am looking for a way to load it into a typescript file so that I can call its methods in the ts file.

<script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script>

There are a few things from the script that I need to have in order to call my typescript file, which

let paymentForm = new SqPaymentForm();

and

paymentForm.requestCardNonce();

I am trying to make SquareUp payments and they have an example: https://docs.connect.squareup.com/articles/adding-payment-form

However, this example does not translate well into the typescript setting that I use. Thanks for the help!

+4
source share
1 answer

You need to include the script in index.html and import it into the component, for example.

declare var SqPaymentForm:any;
import "https://js.squareup.com/v2/paymentform";

, , , JS.

. , , , , , JS .

+2

Source: https://habr.com/ru/post/1677193/


All Articles