How to include an external Javascript file in the angular?

Asked

Viewed 957 times

1

In my old projects I had conditions that take advantage of most of my css codes when I started creating my projects in Angular, while searching I learned of a file called Styles.css that is inside the src folder and inside it the app folder.

That part was easy, which is a challenge and how to include my old javascript files

see how I used to link my javascript files

<script src="assets/js/plugins.js"></script>
<script src="assets/js/main.js"></script>


<script src="assets/js/lib/chart-js/Chart.bundle.js"></script>
<script src="assets/js/dashboard.js"></script>
<script src="assets/js/widgets.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.min.js"></script>
<script src="assets/js/lib/vector-map/jquery.vmap.sampledata.js"></script>
<script src="assets/js/lib/vector-map/country/jquery.vmap.world.js"></script>

I searched through my project angle and I couldn’t find a way to include them in the project, could someone please explain to me to include them in my project?

I tried to put it like this;

<script src="js/teste.js" type="text/javascript"></script>

I put the test.js file inside the src folder and inside the src folder I created a js folder and put it inside, but did not solve it and generated an error in the browser console

  • 1

    https://github.com/angular/angular-cli/wiki/stories-global-scripts

  • you’re using angular-cli?

1 answer

1


One way I’m using it is to take these calls and put it on the index of your angular project, and throw all the content into the Assets folder, it’s going to roll, there are other ways, only more laborious, especially when you have a bootstrap template ready to move to an angular 2 or higher project

Browser other questions tagged

You are not signed in. Login or sign up in order to post.