How can use external js files into angular.json in angular 6

2.3k views Asked by At

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?

2

There are 2 answers

0
Abdul Jabbar On

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"
]
0
Alex Onozor On
"styles":[ 
"/style.css"
],

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

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