Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include script tag while Angular2 running ?

Tags:

angular

How to include this external java script library inside Angular2 page view .

I want to include this

 <!-- google maps javascript -->
 <script src="//maps.googleapis.com/maps/api/js?key=#######&sensor=true"></script>

so when this page is in view this library is loaded and start working .

like image 496
Amr Ibrahim Avatar asked Jun 01 '26 21:06

Amr Ibrahim


1 Answers

You can't.
The Angular processor remove all script tag in the template files for a security reason.


Alternatives:

  • Put your script in the index.html
  • Import it directly in your component .ts file using import 'path/to/file'.
like image 137
Maxime Gélinas Avatar answered Jun 03 '26 12:06

Maxime Gélinas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!