0

I am trying to configure an web app with requireJS and angularJS. I come from marionette configuration and I am trying to have a similar one in angular (in concepts like views and controllers) first so I want to be able to map #/test to my controller and log in the console one message.

I've seen Does AngularJS support AMD like RequireJS? and RequireJS and AngularJS and I kind of got the differences and from my point of view my config should work... but it does not...

Here is my code:

File: app.config.js

require.config({
    shim: {
        angular: {
            exports: 'angular'
        },
        angularRoute: ['angular']
    },
    paths: {
        angular: '../lib/angular',
        angularRoute: '../lib/angular-route'
    }
});

require(['angular', 'app', 'routes/index'], function (angular) {
    angular.bootstrap(document, ['app']);
});

File: app.js

define(['angular', 'angularRoute'], function (angular) {
    //angular.module('app.controllers', []);
    var app = angular.module('app', ['ngRoute']);
    return app;
});

File: routes/index.js

define(['angular', 'app', 'controllers/index'], function (angular, app) {
    app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/', { templateUrl: require.toUrl('/resources/js/app/templates/test.html'), controller: 'indexController'});
    }]);
});

File: controllers/index.js

define(['angular', 'app'], function (angular, app) {
    //var appControllers = angular.module('app.controllers');
    app.controller('indexController', ['$scope', function ($scope) {
        console.log('cascade...');
    }]);
});

What am i missing? When i access #/test, i don't see "cascade" in the console, should I?.. Right?

Thanks in advance.

3
  • @AlvaroJoao It does not show "cascade" in the console. It means that the controller does not get called? Commented Oct 3, 2015 at 15:43
  • Can you post the html you are calling the require and the controller? Commented Oct 3, 2015 at 16:32
  • @AlvaroJoao This one github.com/jaxkodex/peru-extremo/blob/master/pe-parent/pe-web/… this file does not show on network tab in chrome dev tools Commented Oct 3, 2015 at 17:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.