0

I've checked out some other questions that have similar errors and they seem to indicate that I could have a syntax error. I've double checked and linted my code, though, and am not sure what's wrong. I've defined a register controller, but it seems that it's not being recognized for some reason.

Relevant files should be the register.controller.js file, which is in static/js/, and myApp.js, which is in static. I've added some of the other config files here for context:

myApp.js

(function () {
  'use strict';

  angular
    .module('myApp', [
      'myApp.config',
      'myApp.routes'
      //'myApp.accounts',

    ]);

  angular
    .module('myApp.config', []);

  angular
    .module('myApp.routes', ['ngRoute']);

  console.log(angular);
  angular
    .module('myApp')
    .run(run);

  run.$inject = ['$http'];

  /**
  * @name run
  * @desc Update xsrf $http headers to align with Django's defaults
  */
  function run($http) {
    $http.defaults.xsrfHeaderName = 'X-CSRFToken';
    $http.defaults.xsrfCookieName = 'casrftoken';
  }
})();

myApp.routes.js

(function () {
    'use strict';

    angular
      .module('myApp.routes')
      .config(config);

    config.$inject = ['$routeProvider'];

    /**
    * @name config
    * @desc Define valid application routes
    */
    function config($routeProvider) {
      $routeProvider.when('/register', {
        controller: 'RegisterController',
        controllerAs: 'vm',
        templateUrl: '/static/templates/authentication/register.html'
      }).otherwise({
        redirectTo: '/'
      });
    }

})();

/static/js/authentication/controllers/register.controller.js

/**
* Register controller
* @namespace myApp.authentication.controllers
*/
/**
* Register controller
* @namespace kiwi.authentication.controllers
*/
(function () {
  'use strict';

  angular
    .module('kiwi.authentication.controllers')
    .controller('RegisterController', RegisterController);

  RegisterController.$inject = ['$location', '$scope', 'Authentication'];

  /**
  * @namespace RegisterController
  */
  function RegisterController($location, $scope, Authentication) {
    var vm = this;

    vm.register = register;

    /**
    * @name register
    * @desc Register a new user
    * @memberOf kiwi.authentication.controllers.RegisterController
    */
    function register() {
      Authentication.register(vm.email, vm.password, vm.username);
    }
  }
})();

/static/js/authentication/authentication.module.js

(function () {
  'use strict';

  angular
    .module('myApp.authentication', [
      'myApp.authentication.controllers',
      'myApp.authentication.services'
    ]);

  angular
    .module('myApp.authentication.controllers', []);

  angular
    .module('myApp.authentication.services', ['ngCookies']);
})();
orange1
  • 2,871
  • 3
  • 32
  • 58

1 Answers1

0

I was missing a module registration -- myApp.js should have been:

angular
.module('myApp', [
  'myApp.config',
  'myApp.routes',
  'myApp.authentication'

])

troubleshooted using the answer to this question: Controller not a function, got undefined, while defining controllers globally

Community
  • 1
  • 1
orange1
  • 2,871
  • 3
  • 32
  • 58