4

I use angular.ui.router to manage routing in my single page application. A part of the configuration looks like this:

.state('app.mymodule', {
    url: '/mymodule',
    resolve: loadSequence('ngResource', 'MyModule'),
    template: '<div ui-view class="fade-in-up"></div>',
    abstract: true
})
.state('app.mymodule.overview', {
    url: '/overview',
    templateUrl: "assets/views/mymodule/overview.html",
    title: 'Overview',
    role: 'systemadmin',
    ncyBreadcrumb: {
        label: 'Overview'
    }
});

The "MyModule" in resolve is an array for several files where I define the angular.module and a service and a controller:

'MyModule': [
    'assets/js/mymodule/mymodule.js',
    'assets/js/mymodule/project/Project.js',
    'assets/js/mymodule/project/ProjectService.js',
    'assets/js/mymodule/project/ProjectCtrl.js',
],

Now when I request the route in my app, sometimes the resource are all loaded correctly:

[Info] ocLazyLoad.componentLoaded – ["MyModule", "factory", "ProjectREST"] (3) (angular.min.js, line 107)
[Info] ocLazyLoad.componentLoaded – ["MyModule", "service", "ProjectService"] (3) (angular.min.js, line 107)
[Info] ocLazyLoad.componentLoaded – ["MyModule", "register", "ProjectCtrl"] (3) (angular.min.js, line 107)
[Info] ocLazyLoad.moduleLoaded – "MyModule" (angular.min.js, line 107)

But sometimes, the log looks like this:

[Info] ocLazyLoad.componentLoaded – ["MyModule", "factory", "ProjectREST"] (3) (angular.min.js, line 107)
[Info] ocLazyLoad.componentLoaded – ["MyModule", "service", "ProjectService"] (3) (angular.min.js, line 107)
[Info] ocLazyLoad.moduleLoaded – "MyModule" (angular.min.js, line 107)
[Info] ocLazyLoad.fileLoaded – "assets/js/mymodule/project/ProjectCtrl.js" (angular.min.js, line 107)

So ocLazyLoad does not register the controller as controller, but just loads the file after the module is completed. This happens randomly and without any changes in the code. Then of course the controller is not recognized by the view and ng:areq (Bad Argument) error is thrown..

What could be the problem here? Is ocLazyLoader loading asynchronously and not in the right order?

PS: the general structure with routing and lazyloading was introduced by the AngularJS template ClipTwo that I'm currently using.

Giacomo Voß
  • 997
  • 8
  • 17

0 Answers0