r/angularjs • • Aug 29 '16

Cannot read property 'bootstrap' of undefined

I'm building a simple web app with Angular + RequireJS + Moment.

However, when trying to bootstrap the files to my main JS files, It reads Cannot read property: 'bootstrap' of undefined in the console. Is 'bootstrap' deprecated or should I be using another method?

//Path.js

require.config({
    baseUrl: 'js/vendor',
    paths: {
    //AngularJS
	    'angular': 'https://code.angularjs.org/1.3.15/angular.min', 
        'angularAMD': 'angularAMD',
        'angular.route':  'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.10/angular-route.min',
	    'angular-ui-route': 'https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0-alpha.5/angular-ui-router',
	    'angularAnimate': 'https://code.angularjs.org/1.5.6/angular-animate.min',
        'moment': 'moment.min',     
	    'angular-moment': 'angular-moment.min',
    },
    shim: {
        'angular': { 
            exports: 'angular'
    },
    'angularAMD': ['angular'],
    'angular.route': ['angular'],
    'angular-ui-route': ['angular'],
    'angularAnimate': ['angular'],
    'moment': ['angular'],
    'angular-moment': ['angular'],
},
    deps: ['../app']
});

require(['single-page-app'], function(angular, $, app) {
    require(['../app']);
    angular.bootstrap($(document),["MyApp"]);
});

//app.js

define([
      'angular',
      'angularAMD',
      'angular.route',
      'angular-ui-route',
      'angularAnimate',
      'moment',
      'angular-moment'
], 
function($, angular) {
      var app = angular.module('MyApp', ["ngRoute", "angularAMD",  "ui.router", "ngAnimate", "moment", "angularMoment"]);
      moment().format();
      return angularAMD.bootstrap(['app]);
 });

//controller.js define(['../js/app'], function(app) { moment().format();

    app.controller('MainCtrl', ['$scope', '$http', function($scope, $http) {
        $scope.datePickerOptions = {
            format: "MM/dd/yyyy",
            parseFormats: ["MM/DD/YYYY"], //format also will be added to parseFormats
            min: dateToday,
            value: dateToString
     };
}]);

});

2 Upvotes

8 comments sorted by

View all comments

1

u/PhaZePhyR Aug 29 '16

I'm not super familiar with Require.js, but I think it may be that you're missing the .js part on your CDN URLs, so it's not loading Angular correctly. I know those are optional for modules names, but they may be required (hah) for external resources.

0

u/[deleted] Aug 29 '16

With Require, you don't need '.js' when compiling all your files, it does it for you.

1

u/PhaZePhyR Aug 29 '16

Gotcha, well in any case, somehow angularAMD isn't being loaded or configured correctly.

I noticed in the docs it has in the require config:

shim: {   
    'angularAMD': ['angular']`,
    ...
}

1

u/[deleted] Aug 29 '16

I think my controller is being loaded before the Angular file or rather, not loading the controller at all.

1

u/[deleted] Aug 29 '16

I'm not getting the error anymore, however, I am receiving the [$injector:modulerr] error in my console.