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

2
  • Why are you doing this explicitly. everything in assets folder is automatically served Commented Dec 12, 2018 at 9:51
  • first time script is not loading after refresh the window it load the script so that i have used Commented Dec 12, 2018 at 10:00

1 Answer 1

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.

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

2 Comments

Or in angular.json for the current version of the CLI : github.com/angular/angular-cli/wiki/stories-global-scripts
if i add the script in angular json in first time while refreshing the page it has load

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.