angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Scripts not being loaded when changing routes

Open ntombela opened this issue 8 years ago • 5 comments

I have an Angular CLI application that consists of multiple components. The issue is that when navigating from component A to component B, component B will loose bindings to the external scripts. I added the external scripts using the recommended way of using app[0].scripts.

What I've observed is that scripts are only loaded when I refresh the page.

I would like guidance as to what I'm doing wrong. Details of my solution and environment setup are provided below.

Version details: Angular CLI: 1.7.0 Node: 8.9.4 OS: win32 x64 Angular: 5.2.5

Repo https://github.com/ntombela/angular-demo

ntombela avatar Feb 17 '18 01:02 ntombela

Add scripts globally as: Try to add the script file as globally on the file .angular-cli.json Add the path of the script files like this in the file

"scripts": [
      "script.js"
]

Remove the other imports.

athulreji avatar Feb 17 '18 02:02 athulreji

I'm not following. What file is script.js?

ntombela avatar Feb 17 '18 06:02 ntombela

the external script

athulreji avatar Feb 18 '18 01:02 athulreji

Got it right. Thanks. I had to subscribe to the router events to know when navigation has ended and then load the scripts.

ntombela avatar Feb 18 '18 19:02 ntombela

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.