I'm building an Address Book to learn angular and have it working nicely until I try to use the route manager. The issue is with loading the angular route manager via require. I'm getting the following error 'Uncaught object'.
There have been questions about this but they have been removed by the user, and other answers point to not having included the ngRoute dependancy in the ng.module dependancy list, or aren't using require at all. I'm not having much luck finding an answer!
I have the an HTML file that includes a require config file:
requirejs.config({
paths: {
'jquery': ['//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min'],
'angular': ['//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min','angular_1.2.16.min'],
'angular-route': ['//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.min','angular-route_1.2.16.min'],
},
shim: {
'jquery': {
exports: 'jquery'
},
'angular': {
exports: 'angular'
},
'angular-route': {
exports: 'ngRoute',
deps: ['angular']
}
},
baseUrl: 'js/lib'
})
require(['modules/ContactsMod'], function() { });
and this is the ContactsMod.js file called at the end of the config file:
define(['jquery', 'angular-route','angular','controllers/ContactsCtrl','routes/ContactsRout'],function($,ngRoute,ng,controller,router) {
// var contactsApp = ng.module('contactsApp', [ngRoute]);
// contactsApp.config(function ( $routeProvider, $locationProvider ){
// $log.debug( "Configuring $routeProvider...");
//
// $locationProvider.html5Mode(true); //?????
//
// $routeProvider
// .when( '/', {
// templateUrl : "views/Contacts.html",
// controller : "controller"
// })
// .otherwise({ redirectTo: '/' })
// })
var contactsApp = ng.module('contactsApp', []);
contactsApp.controller(controller);
ng.bootstrap(document, ['contactsApp']);
});
The commented out section is the part I'm trying to figure out. The above version works, but when I try to add the ngRoute dependancy to the ng.module call in the commented out part I get the error mentioned.
I can see that all the assets have been loaded before the module is called. But I can also see that the ngRoute logs out as undefined so it makes sense that it doesn't work! I've tried a number of different config variants. Like including the angular-route as a dependancy of angular (which give the same error plus another of 'Uncaught TypeError: Cannot read property 'module' of undefined').
I can see there's a seed app that uses custom async loader instead of require... what do you recommend?
I don't know how to debug this problem, any help or pointers appreciated!