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 .

2

1 Answer 1

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'.
Sign up to request clarification or add additional context in comments.

3 Comments

how to include googlmaps script at runtime ?
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)
Just see how Angular tell us to include RxJs and use the same method. angular.io/docs/ts/latest/guide/… JSFiddle or CodePen are not very good to show Angular2 app example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.