简体   繁体   中英

How to execute function from cdn script in typescript

I have a question. I have a script which i am adding like:

<script
  id="TestJS"
  src="https://test/uc.js"
  data-culture="EN"
  type="text/javascript"
></script>

Script is referenced in index.html in my angular app. I would like to use function from that script , something like:

 if (getConsent('testParam'))
   {--do something with it--}

My problem is when i try to call it like that in typescript i am getting errors. Any idea how can i archive this?

I solve it like this:

 private giveConsentJS= window as any;
 public isConsentGiven: boolean;

and then in init:

this.isConsentGiven= this.giveConsentJS.getConsent('someParam');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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