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.

Community
  • 1
  • 1
jaxkodex
  • 484
  • 2
  • 6
  • 17

0 Answers0