ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Random issue with non-loaded libraries and router #326

Open gen4sp opened 8 years ago

gen4sp commented 8 years ago

I use ocLazyLoad with router

.state("profile", {
      url: "/profile",
      templateUrl: "/views/profile/main.html",
      data: {pageTitle: 'User Profile'},
      controller: "UserProfileController",
      resolve: {
        deps: ['$ocLazyLoad', function ($ocLazyLoad) {
          return $ocLazyLoad.load({
            name: 'MetronicApp',
            insertBefore: '#ng_load_plugins_before', // load the above css files before '#ng_load_plugins_before'
            files: [
              '/assets/global/plugins/typehead-js/typeahead.bundle.min.js',
              '/assets/global/plugins/typehead-js/bloodhound.min.js',
              '/assets/global/plugins/angularjs/plugins/angular-typeahead.min.js',

              '/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css',
              '/assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js',
              '/assets/global/plugins/angularjs/plugins/angular-bootstrap-switch/angular-bootstrap-switch.min.js',

              '/assets/global/plugins/morris/morris.css',
              '/assets/global/plugins/morris/morris.min.js',
              '/assets/global/plugins/morris/raphael-min.js',

              '/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css',
              '/assets/pages/css/profile.css',

              '/assets/global/plugins/jquery.sparkline.min.js',
              '/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js',

              '/assets/pages/scripts/profile.js',

              '/js/controllers/UserProfileController.js'
            ]
          });
        }]
      }
    })

Sometimes I experience errors like $(...).tooltip is not a function or other similar ones

It happens randomly and somehow connected with navigation through pages and refreshing page.

My thought is some libraries are not loaded in sequence or there are some hidden errors during loading.

How can I debug it? Are the files loading sequentially or parallel?

Glad for any help. Thanks!