简体   繁体   中英

Angular 4 pages do not see custom JS files without refreshing the page

I have some custom js files and I import all of them in angular-cli.json file. The problem is that the pages don't see them without refreshing pages after routing from one page to another.

angular-cli.json file :

"styles": [
        "styles.css",
        "./assets/plugins/bootstrap/css/bootstrap.css",
        "./assets/plugins/node-waves/waves.css",
        "./assets/plugins/animate-css/animate.css",
        "./assets/plugins/morrisjs/morris.css",
        "./assets/plugins/jquery-datatable/skin/bootstrap/css/dataTables.bootstrap.css",
        "./assets/css/style.css",
        "./assets/css/themes/all-themes.css"
      ],
      "scripts": [
        "./assets/plugins/jquery/jquery.min.js",
        "./assets/plugins/bootstrap/js/bootstrap.js",
        "./assets/plugins/bootstrap-select/js/bootstrap-select.js",
        "./assets/plugins/jquery-slimscroll/jquery.slimscroll.js",
        "./assets/plugins/node-waves/waves.js",
        "./assets/plugins/jquery-countto/jquery.countTo.js",
        "./assets/plugins/raphael/raphael.min.js",
        "./assets/plugins/morrisjs/morris.js",
        "./assets/plugins/chartjs/Chart.bundle.js",
        "./assets/plugins/flot-charts/jquery.flot.js",
        "./assets/plugins/flot-charts/jquery.flot.resize.js",
        "./assets/plugins/flot-charts/jquery.flot.pie.js",
        "./assets/plugins/flot-charts/jquery.flot.categories.js",
        "./assets/plugins/flot-charts/jquery.flot.time.js",
        "./assets/plugins/jquery-sparkline/jquery.sparkline.js",
        "./assets/plugins/jquery/jquery.min.js",
        "./assets/plugins/bootstrap/js/bootstrap.js",
        "./assets/plugins/node-waves/waves.js",
        "./assets/plugins/jquery-validation/jquery.validate.js",
        "./assets/plugins/jquery-datatable/jquery.dataTables.js",
        "./assets/plugins/jquery-datatable/skin/bootstrap/js/dataTables.bootstrap.js",
        "./assets/plugins/jquery-datatable/extensions/export/dataTables.buttons.min.js",
        "./assets/plugins/jquery-datatable/extensions/export/buttons.flash.min.js",
        "./assets/plugins/jquery-datatable/extensions/export/jszip.min.js",
        "./assets/plugins/jquery-datatable/extensions/export/pdfmake.min.js",
        "./assets/plugins/jquery-datatable/extensions/export/vfs_fonts.js",
        "./assets/plugins/jquery-datatable/extensions/export/buttons.html5.min.js",
        "./assets/plugins/jquery-datatable/extensions/export/buttons.print.min.js",
        "./assets/js/admin.js",
        "./assets/js/pages/tables/jquery-datatable.js",
        "./assets/js/pages/examples/sign-in.js",
        "./assets/js/pages/index.js",
        "./assets/js/demo.js"
      ]

app.module.ts :

RouterModule.forRoot([  
      {
          path: 'Main', component: MainComponent, canActivate: [], children: [
              { path: '', component: HomeComponent },
              { path: 'Users', component: UsersComponent },
          ]
      },
      { path: 'Login', component: LoginComponent },
      { path: '**', redirectTo: 'Login' }
  ])

您确定要使用ngOnit触发它们吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM