0

For my project I need to install the "Loadingbar.js" lib to one of my pages (which you can find here: https://loading.io/progress/). I did paste the CSS in my global "style.css" file.

So, first, I just tried to put the <script></script> in my index:

<script type="text/javascript" src="assets/js/loading-bar.js"></script>

It worked for few hours, and now it does not work anymore. So I tried everything: I tried to put the <script> everywhere on each line of my index.html or even in the html of my page, in the body, under the body, under the <app-root></app-root>... nothing worked.

Also, the Angular project is sometime trolling me: the js is loaded once very rarely. If I refresh the page without changing anything- it does not work anymore.

I tried to add "defer" to the <script></script>.

I tried to wait document ready, I tried the setTimeout, but it never worked.

I tried to add the path to the script in "angular.json", didn't work.

What can I do to make this work? How do I add JS lib to an angular project?

Thanks.

2 Answers 2

1

First thing you should know is that in angular applications it's better to use npm dependency of any library if possible. If this is not possible and you need to use external js files, you can follow these steps:

  1. First, put your js inside the node_modules folder. eg: node_modules/test-lib/loading-bar.js

  2. Inside your app.module.ts, you can put this line at top of the file:

    import test-lib/loading-bar.js(without node_modules)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but if I use that, I can't push my project on Git because the node_module folder isn't pushed.
0

Loading.io links their library to their GitHub account.

They offer an Angular example here: https://github.com/loadingio/angular-loading-bar

It looks like the best approach is to install the library via npm or yarn.

1 Comment

Thanks, the library is not working, some imports arn't true like the "ldBar" import

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.