0

This is my code

ngOnInit() {
   this.loadScript('./assets/js/jquery.dataTables.min.js');
   this.loadScript('./assets/js/datatable.js');
   this.loadScript('./assets/js/common.js');
}

When page loading each time js has loadedenter image description here

mika
  • 343
  • 1
  • 14
Gayu. Akilan
  • 13
  • 1
  • 1
  • 5

1 Answers1

2

You shouldn't do the loading of your scripts in the ngOnInit(), that way it will happen mulitple times. You can add your scripts do the .angular-cli.jsonfile, to do this have a look at this answer.

Or for the current CLI in the angular.json, refer to this for more information.

mika
  • 343
  • 1
  • 14
  • 1
    Or in `angular.json` for the current version of the CLI : https://github.com/angular/angular-cli/wiki/stories-global-scripts – Gilsdav Dec 12 '18 at 10:02
  • if i add the script in angular json in first time while refreshing the page it has load – Gayu. Akilan Dec 12 '18 at 10:04