ocombe / ocLazyLoad

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

DashboardController not aNaNunction got undefined with OClazy loading #294

Open mnaouali opened 8 years ago

mnaouali commented 8 years ago

I'm trying to lazy load my JS files with oclazyload module. but I'm getting this error

Uncaught ReferenceError: dashboardController is not defined

while my files are correctly loaded. here is the state declaration

.state(
            "dashboard",
            {
                url : "/dashboard",
                views : {

                    "mainbody" : {
                        templateUrl : "dashboard/dashboard.html"
                    },
                },
                resolve : {
                    load : [
                            '$ocLazyLoad',
                            function($ocLazyLoad) {
                                return $ocLazyLoad
                                        .load({
                                            name : 'Dashboard',
                                            files : [
                                                    'dashboard/Dashboard.js',
                                                    'dashboard/controllers/DashboardController.js' ]
                                        });
                            } ]
                },
                data : {
                    pageTitle : "dashboard",
                    authenticate : true
                }
            })

and my module was declared like this:

angular.module('Dashboard', [ 'nvd3', 'ngAnimate', 'ui.bootstrap', 'ngTouch', 'ui.grid' ]).controller('dashboardController', dashboardController);

and the controller

function dashboardController ($scope , uiGridConstants, $http,  $timeout) {//some staff}

any idea how to fix that?

ocombe commented 8 years ago

Hello,

change your controller code to:

angular.module('Dashboard').controller(function dashboardController ($scope , uiGridConstants, $http,  $timeout) {
  //some stuff
});
mnaouali commented 8 years ago

Hi Olivier,

Thank you for your update, in fact I tried that and it's not always working, I always get this error in the Chrome console : dashboardController is not defined. that's related to the Dashboard.js file. but the display is correct. And some times I get the previous error with nothing displayed in the HTML. the complete error message is

Error: [ng:areq] http://errors.angularjs.org/1.5.0-rc.0/ng/areq?p0=dashboardController&p1=not%20aNaNunction%2C%20got%20undefined
at Error (native)
at http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:6:421
at sb (http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:22:41)
at Ta (http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:22:128)
at http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:84:42
at B (http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:62:118)
at v (http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:63:115)
at g (http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:56:341)
at http://localhost:8080/static/js/fmk/angular.min.v1.5.0-rc.0.js:55:484
at http://localhost:8080/static/js/fmk/angular-ui-router.js:3866:9

Am I Missing Something?

ocombe commented 8 years ago

Sorry, the syntax was wrong I forgot the name of the controller. It should be:

angular.module('Dashboard').controller("dashboardController", function dashboardController ($scope , uiGridConstants, $http,  $timeout) {
  //some stuff
});
mnaouali commented 8 years ago

yes, I updated that, but still have the same error. I don't know why it's not working all the time. here is my controller

angular.module('Dashboard').controller('dashboardController',['$scope' , 'uiGridConstants', '$http',  '$timeout', function dashboardController ($scope , uiGridConstants, $http,  $timeout) { // some stuff}]);

but I still have the same error :'(

in fact I have a routing module where I defined all my templates using ui-router then I added the resolve with lazy load of module and files. the modules are defined only in this part. should I define them also in the global module?

Sakthi002 commented 6 years ago

am i too