ocombe / ocLazyLoad

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

TypeError: Cannot read property 'config' of undefined #388

Closed biswa007 closed 7 years ago

biswa007 commented 7 years ago

This is my main app js codes

`(function(){ ;"use strict"; var app = angular.module('lfclient', ['ngResource', 'ngMessages', 'ngAnimate', 'toastr', 'ui.router', 'oc.lazyLoad', 'satellizer']); app.config(['$ocLazyLoadProvider', '$stateProvider', '$urlRouterProvider', '$authProvider', function($rootScope, $stateProvider, $urlRouterProvider, $authProvider, $ocLazyLoadProvider) {

/**/
$ocLazyLoadProvider.config({
    'debug': false, // For debugging 'true/false'
    'events': true, // For Event 'true/false'
    'modules': [{ // Set modules initially
        name : 'devicemap', 
        files: ['uikit/jqvmap/dist/maps/jquery.vmap.world.js']
    },{
        name : 'formvalid', 
        files: ['uikit/validator/validator.js']
    }]
});

/**
 * Helper auth functions
 */
var skipIfLoggedIn = ['$q', '$auth', function($q, $auth) {
  var deferred = $q.defer();
  if ($auth.isAuthenticated()) {
    deferred.reject();
  } else {
    deferred.resolve();
  }
  return deferred.promise;
}];

var loginRequired = ['$q', '$location', '$auth', function($q, $location, $auth) {
  var deferred = $q.defer();
  if ($auth.isAuthenticated()) {
    deferred.resolve();
  } else {
    $location.path('/');
  }
  return deferred.promise;
}];

/**
 * App routes
 */
$stateProvider
  .state('login', {
    url: '/',
    templateUrl: 'partials/login.html',
    controller: 'LoginController',
    resolve: {
      skipIfLoggedIn: skipIfLoggedIn
    }
  })
  .state('signup', {
    url: '/signup',
    templateUrl: 'partials/signup.html',
    controller: 'SignupController',
    resolve: {
      skipIfLoggedIn: skipIfLoggedIn
    }
  })
 .state('logout', {
    url: '/logout',
    template: null,
    controller: 'LogoutCtrl'
  })

  /*.state('devices', {
    url: '/devices',
    templateUrl: 'partials/device.html',
    controller: 'DeviceController',
    resolve: {
      loginRequired: loginRequired
    }
  })*/

  .state('dashboard', {
    url: '/dashboard',
    templateUrl: 'partials/dashboard.html',

    views:{
        '':{templateUrl: 'partials/dash_content.html',
            controller: 'dashboardController'
           }
    },
     resolve: {
      loginRequired: loginRequired
    }
  })

 .state('dashboard.cont',{
    url: '/cont',
    templateUrl: 'partials/dash_content.html',
    controller: '',
    resolve: {
        loginRequired: loginRequired
    }
})
 .state('dashboard.device',{
    url: '/device',
    templateUrl: 'partials/device.html',
    controller: 'DeviceController',
    resolve: {
        loginRequired: loginRequired
    }
})

 .state('profile', {
    url: '/profile',
    templateUrl: 'partials/profile.html',
    controller: 'ProfileController',
    resolve: {
      loginRequired: loginRequired
    }
  });
$urlRouterProvider.otherwise('/');

/**
 *  Satellizer config
 */
$authProvider.facebook({
  clientId: '123'
});

$authProvider.google({
  clientId: '456'
});

}]);

})();`

and its giving this error

TypeError: Cannot read property 'config' of undefined at http://127.0.0.1:3000/app.js:7:24

Am I missing something?? Please help thanks

kuroky360 commented 7 years ago

It is not the issue of ocLazyLoad. you can do it like this:

app.config(['$rootScope', '$stateProvider', '$urlRouterProvider', '$authProvider','$ocLazyLoadProvider', function($rootScope, $stateProvider, $urlRouterProvider, $authProvider, $ocLazyLoadProvider){
...
}

It works~

biswa007 commented 7 years ago

my mistake

thanku @Kuroky360