Один из моих угловых контроллеров не найден - PullRequest
0 голосов
/ 10 октября 2018

Хорошо, я знаю, что этот вопрос задавали много, но я действительно не уверен, что я пропустил.Этот код работал в какой-то момент, я оставил его на некоторое время, затем добавил другой маршрут (логин), и теперь RegisterController не работает.Я получаю Error: [ng:areq] Argument 'RegisterController' is not a function, got undefined

маршрутизацию:

(function () {
  'use strict';

  angular
    .module('thinkster.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'
    }).when('/login', {
       controller: 'LoginController',
       controllerAs: 'vm',
       templateUrl: '/static/templates/authentication/login.html'
    }).otherwise('/');
  };
})();

register.controller.js

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

  angular
    .module('thinkster.authentication.controllers', [])
    .controller('RegisterController', RegisterController);

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

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

    vm.register = register;

    activate();

    /**
    * @name activate
    * @desc Actions to be performed when this controller is instantiated
    * @memberOf thinkster.authentication.controllers.RegisterController
    */
    function activate() {
     // If the user is authenticated, they should not be here.
      if (Authentication.isAuthenticated()) {
       $location.url('/');
      }
    }

    /**
    * @name register
    * @desc Register a new user
    * @memberOf thinkster.authentication.controllers.RegisterController
    */

    // this will store the status so I can access it in the HTML
    vm.error_status = ''

    function register() {
      // if t
      Authentication.register(vm.email, vm.password, vm.username).catch(function errorCallback(error){
        //save the result of the promise to a variable
        //var result = error.status;
        vm.error_status += error.status
        console.log(vm.error_status)
      })
    }

  }
})();

Но мой LoginController загружен просто отлично:

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

  angular
    .module('thinkster.authentication.controllers', [])
    .controller('LoginController', LoginController);

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

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

    vm.login = login;

    activate();

    /**
    * @name register
    * @desc Register a new user
    * @memberOf thinkster.authentication.controllers.RegisterController
    */

    // this will store the status so I can access it in the HTML
    vm.error_status = ''


    function activate() {
      //If the user is authenticated, they should not be here

      if (Authentication.isAuthenticated()) {
        $location.url('/')
      }
    }

    function login() {
      Authentication.login(vm.email, vm.password)
    }
  }
})();

javascripts.html:

{% load compress %}
{% load staticfiles %}

{% compress js %}
<script type="text/javascript" src="{% static 'bower_components/jquery/dist/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/bootstrap/dist/js/bootstrap.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/bootstrap-material-design/dist/js/material.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/bootstrap-material-design/dist/js/ripples.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/underscore/underscore.js' %}"></script>

<script type="text/javascript" src="{% static 'bower_components/angular/angular.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/angular-route/angular-route.js' %}"></script>
<script type="text/javascript" src="{% static 'bower_components/angular-cookies/angular-cookies.js' %}"></script>

<script type="text/javascript" src="{% static 'bower_components/ngDialog/js/ngDialog.js' %}"></script>
<script type="text/javascript" src="{% static 'lib/snackbarjs/snackbar.min.js' %}"></script>

<script type="text/javascript" src="{% static 'javascripts/thinkster.js' %}"></script>

<script type="text/javascript" src="{% static 'javascripts/thinkster.config.js' %}"></script>
<script type="text/javascript" src="{% static 'javascripts/thinkster.routes.js' %}"></script>
<script type="text/javascript" src="{% static 'javascripts/authentication/authentication.module.js' %}"></script>
<script type="text/javascript" src="{% static 'javascripts/authentication/services/authentication.service.js' %}"></script>
<script type="text/javascript" src="{% static 'javascripts/authentication/controllers/register.controller.js' %}"></script>
<script type="text/javascript" src="{% static 'javascripts/authentication/controllers/login.controller.js' %}"></script>
{% endcompress %}

Маршрутизация работает, потому что если я изменю имя «RegisterController» на «RegController», то это имя будет отображаться в журнале консоли.Кто-нибудь может определить здесь какие-либо проблемы?

Кроме того, есть ли приложение или что-то, что может дать мне более подробную информацию о том, где мои файлы работают неправильно?

1 Ответ

0 голосов
/ 10 октября 2018

Чарльз Смит, вы должны создать один модуль thinkster.authentication.controllers

например,

(function () {
   'use strict';
    angular.module('thinkster.authentication.controllers', []);
})();

, а затем добавить в этот модуль новые ролики:

(function () {
  'use strict';

 angular.module('thinkster.authentication.controllers')
        .controller('LoginController', LoginController);

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

 [...]
)();

добавление массива в качестве второго параметра angular.module запускает этот модуль заново, но вы используете одно имя модуля.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...