-1

i have external javascript file. I want to use it in .ts file without converting it. Anyone have idea to use it inside typescript without converting.

Satyajit Behera
  • 368
  • 2
  • 13
  • https://stackoverflow.com/questions/41219542/how-to-import-js-modules-into-typescript-file – Uthistran Selvaraj Feb 17 '20 at 18:50
  • Does this answer your question? [How to import js-modules into TypeScript file?](https://stackoverflow.com/questions/41219542/how-to-import-js-modules-into-typescript-file) – Quethzel Diaz Feb 17 '20 at 20:50

1 Answers1

0

Option 1

Place your script inside the src\assets folder.

Include the script in angular.json

"scripts": [
  "src/assets/myscript.js"
]

Option 2

Alternatively, host your script via a CDN (or anywhere really): https://www.cloudflare.com/myscript.js

Then reference that script as you normally would in your HTML:

Index.html

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://www.cloudflare.com/myscript.js"></script>
</head>

<body>
  <app-root></app-root>
</body>

</html>

Michael Kang
  • 52,003
  • 16
  • 103
  • 135