3

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 .

Amr Ibrahim
  • 2,066
  • 2
  • 23
  • 47

1 Answers1

2

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'.
Maxime Gélinas
  • 2,202
  • 2
  • 18
  • 35
  • how to include googlmaps script at runtime ? – Amr Ibrahim Dec 13 '16 at 15:46
  • 1
    Why not `import '//maps.googleapis.com/maps/api/js?key=#######&sensor=true'`? (In the component that need the script so the component require its dependencies) – Maxime Gélinas Dec 13 '16 at 15:49
  • 1
    Just see how Angular tell us to include RxJs and use the same method. https://angular.io/docs/ts/latest/guide/server-communication.html#!#rxjs JSFiddle or CodePen are not very good to show Angular2 app example. – Maxime Gélinas Dec 19 '16 at 21:05