0

I am using angular 4 and i want use my JavaScript file to work globally and i have declared like this. index.html <script src="assets/js/jquery-1.11.1.min.js"></script> <script src="assets/js/bootstrap.min.js"></script>

it is working when i have to use them in app-component.html, but problem is that i have another project which as different folders for different pages it is not working therenot working here.

if use the same code in app.component.html it is working fine, but i have different pages within that app/layouts/projects/, here in projects it is not working when i declare js link in the index.html, it works fine in app folder but not working inside it's sub-folder

4
  • just add jquery and bootstrap to your package.json(webpack) and do npm i or npm install jquery and bootstrap. Then import it your component and use. Commented Feb 5, 2018 at 9:41
  • If you want to add your js stackoverflow.com/questions/44817349/… Commented Feb 5, 2018 at 9:43
  • If you want to add bootstrap and Jquery stackoverflow.com/questions/43557321/… Commented Feb 5, 2018 at 9:46
  • thanks a lot, if i wan't to add any external JavaScript files what should i do like <script src="assets/js/hello.js"></script> Commented Feb 5, 2018 at 9:47

1 Answer 1

0

No need to add jquery directly in html file. You can do this:

1) npm install jquery --save
2) npm install @types/jquery --save
3) in your component : declare var $ :any; 
Sign up to request clarification or add additional context in comments.

7 Comments

thanks a lot, if i wan't to add any external JavaScript files what should i do like <script src="assets/js/hello.js"></script>
you can include extra script in angular-cli.json
Don't include src in path. So path will be : "scripts": ["./assets/js/hello.js"]
yeah i did in the same way, is there any option to declare in index.html and access it.
You can include in index.html file but you should not do it. What error you are getting while declaring in angular-cli ?
|

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.