0

I use requirejs-rails to manage dependencies between client-side modules in my Rails 4 project.

my entry point is:

(function (define, undefined) {
'use strict';

var mainModule = function(angular, routingConfiguration, controllers) {
    var restaurantsApp = angular.module('RestaurantsApplication', ['ui.router'])
    .config(routingConfiguration);

angular.forEach(controllers, function(controller, name){
  restaurantsApp.controller(name, controller);
  });
};

define(['angular', 'application/routing-configuration',
     'controllers', 'angular-ui-router'], 
     mainModule );
})(window.define);

but each module "injected" in define function is undefined. I mean, if I call inside define function

console.log(arguments)

I receive

[undefined, undefined, undefined, undefined]

I thought, that somewhere I have circular references, so I removed all modules except angular

(function (define, undefined) {
'use strict';

var mainModule = function(angular) {
    var restaurantsApp = angular.module('RestaurantsApplication', []);
};

define(['angular'], 
     mainModule );
})(window.define);

but I get same result: angular is undefined.

Updated

requirejs.yml

paths:
  "angular"           : "angular"
  "angular-ui-router" : "angular-ui-router.min"

modules:
  - name: 'entry-point'
Andrew Kovalenko
  • 6,441
  • 2
  • 29
  • 43
  • A bad RequireJS configuration could cause what you are experiencing, but you are not showing the RequireJS configuration in your question. – Louis Mar 05 '14 at 11:17

1 Answers1

0

It seems, I found, what is wrong. Angular doesn't support AMD from the box.

I've configured shim in requierjs.yml like below

shim:
  "angular" :
    exports : "angular"

  "angular-ui-router":
    exports : "angular-ui-router"
    deps : "angular"

and, woo-hoo! it is working!

Andrew Kovalenko
  • 6,441
  • 2
  • 29
  • 43