1

I am starting my adventure with Angular2 and I've read lots of tutorials, but there is one thing I am concern about. Lets say we have two views - one with report and one with upload image.

First view will be handled by - let's say 'ReportComponent' and on html template it will use 'Chart.js' library
Second view will be handled by 'UploadMediaComponent' and on html template it will use 'Dropzone.js'

How to include this javascript libraries on html? In most tutorials I've read the only way to resolve it is to include both libraries in the index.html page (which is consistent with single page application pattern). But in the other hand - do we really need load hundreds of external libraries at once and beggining of loading the app even if we need to use it only in one view (one component)? Let's say I just need to use 'Dropzone.js' on only one view, do I need to load it on every html view on client side?

2

3 Answers 3

1

You could add file in your angular-cli.json configuration file.

Example :

 "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/tether/dist/js/tether.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "../node_modules/highcharts/highcharts.js",
    "../node_modules/chart.js/dist/Chart.js",
    "../node_modules/chart.js/dist/Chart.min.js"    

    ]

directly add all JS build will generate script bundled version , Not needed any imports

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

Comments

0

You could add file in your angular-cli.json configuration file.

Example :

"assets": [
    "path/Dropzone.js" ,
    "path/Chart.js"
  ],

Then directly include file to ReportComponent

<script src="/Chart.js"></script>

and UploadMediaComponent

<script src="/Dropzone.js"></script>

Comments

0

Have you tried to use bower or npm ? after you set it and install the libraries you need with bower install package it adds them to your html the libraries automatically.

Comments

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.