RequireJS + Angular: Undefined application. Callback not removed

I got main.js with this simple code:

'use strickt';

require.config({

  paths: {
    'angular'        : 'libs/angular'          ,
    'angular-router' : 'libs/angular-route'    ,
  },
  shim : {
    'angular' : {
      exports : 'angular'
    },
    'angular-router' : {
      deps: ['angular']
    }
  }

});

require(['app'], function (mainApp) {
  console.log(mainApp);
});

As you can see, I am trying to get the application inside, requiring a callback. But all I got is undefined. Here is what I got inside the app.js file:

define('mainApp', ['angular', 'angular-route'], function (angular) {
  var app = angular.module('mainApp', ['ngRoute']);
  console.log('should be fired from app.js');
  return app;
});

So the question is: The argument to the function 'mainApp' as undefined inside the main.js callback seems logical, because console.log () inside app.js does not remove. Can someone tell me what's wrong with him?

+4
source share
1 answer

Just delete the module name in the app.js file (or change it to "application"). The app.js file will look like this:

define(['angular', 'angular-route'], function (angular) {
  var app = angular.module('mainApp', ['ngRoute']);
  console.log('should be fired from app.js');
  return app;
});

http://requirejs.org/docs/api.html#modulename

, - , . . , , , .

+1

All Articles