amcharts / amcharts3-angular2

Official Angular 2 plugin for amCharts V3
99 stars 35 forks source link

How do I transfer the scripts from the index.html in component where i use chart? #81

Open Egorro opened 6 years ago

Egorro commented 6 years ago
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>

I don't want to load these scripts on initial page load.

thank you.

darlesson commented 6 years ago

When and how are you planning to load the scripts? Are you trying to load them when loading the chart? Are you using something like RequireJS?

I recommend you to check https://www.amcharts.com/kbase/amcharts-meets-requirejs/ if you can use RequireJS and only want to load these files when needed.

Egorro commented 5 years ago

I found a solution: https://medium.com/@zainzafar/angular-load-external-javascript-file-dynamically-3d14dde815cb Load order is important:

this.dynamicScriptLoader
      .load('amcharts') // amcharts should be first
      .then(() => {
        this.dynamicScriptLoader
          .load('amchartsSerial', 'themeLight')
          .then(() => chartMaker());
      })
      .catch(error => console.error(error));