admin 管理员组文章数量: 1086019
I am attempting to add the following script tag to my Angular 2 project, however I am looking for a way to load this into the typescript file so that I can call its methods within the ts file.
<script type="text/javascript" src=""></script>
There are a few things from the script that I need to be able to call in my typescript file, which are
let paymentForm = new SqPaymentForm();
and
paymentForm.requestCardNonce();
I am trying to impletement from SquareUp payments and they have an example here:
However, this example doesn't translate well into the typescript setup that I am using. Thanks for the help!
I am attempting to add the following script tag to my Angular 2 project, however I am looking for a way to load this into the typescript file so that I can call its methods within the ts file.
<script type="text/javascript" src="https://js.squareup./v2/paymentform"></script>
There are a few things from the script that I need to be able to call in my typescript file, which are
let paymentForm = new SqPaymentForm();
and
paymentForm.requestCardNonce();
I am trying to impletement from SquareUp payments and they have an example here: https://docs.connect.squareup./articles/adding-payment-form
However, this example doesn't translate well into the typescript setup that I am using. Thanks for the help!
Share Improve this question edited May 15, 2017 at 17:16 Mike Feltman 5,1761 gold badge18 silver badges39 bronze badges asked May 15, 2017 at 16:35 Jeremy PJeremy P 1,4073 gold badges14 silver badges27 bronze badges1 Answer
Reset to default 5You need to include the script in the index.html and import it into the ponent, like so.
declare var SqPaymentForm:any;
import "https://js.squareup./v2/paymentform";
The declare is required for it to properly pile, otherwise it doesn't know how to wait to link until it is JS.
Note: I have only done this with files that I downloaded, as opposed to access from the web, so if it plains about the import, you may need to download the JS and try that.
本文标签: javascriptLoad Script into TypeScript FileStack Overflow
版权声明:本文标题:javascript - Load Script into TypeScript File? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744046403a2524201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论