1

I have a side bar menu script file, in assets folder that I include into index.html. Whenever I refresh the home/dashboard child route the script will be working, If I'm redirected from the initial route / to home/dashboard the sidebar show/hidden button doesn't work (this logic is part of the script I mentioned) Once I refresh the page, the external scripts will work properly. Here is my routing module

 app.routing.module.ts

 const routes: Routes = [
      { path: '', redirectTo: '/home', pathMatch: 'full' },
      //{ path: 'login', component: LoginComponent,  },
      { path: 'home', component: HomeComponent,
      children:[
        { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
        { path: 'dashboard', component: DashboardComponent,},
        { path: 'totalapproved', component: ApprovedComponent,},
        { path: 'campaign', component: CampaignmanagerComponent,},]}
    ]

Is there any way to add external assets script to angular.json file?

  • Share more details and state your question properly. Unable to understand what you want exactly. – Exterminator Sep 17 '18 at 06:18
  • It's a bit hard to understand your problem exactly,but I think your problem is that y our external script will only execute on initial page load. So if you refresh the page, then navigate to a child route , thenthey will not work. This is normal behaviour – David Sep 17 '18 at 06:55

2 Answers2

0

You can add you external script and style in angular.json file like

"styles":[ 
"src/assets/css/style.css"
],
"scripts"[
"src/assests/js/script.js"
]
Abdul Jabbar
  • 348
  • 2
  • 10
0
"styles":[ 
"/style.css"
],

"scripts"[
"src/script.js"
]

You can also add it to your index.html if you're using CDN.

Alex Onozor
  • 6,841
  • 1
  • 22
  • 26