Я следую учебнику от https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/single и используя структуру от https://docs.angularjs.org/tutorial.Почему «Модуль» myControllers «недоступен» в AngularJS, хотя я уже определил его?
Но я получил эту ошибку:
Uncaught SyntaxError: Unexpected token ]
angular.js:4138 Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module myControllers due to:
Error: [$injector:nomod] Module 'myControllers' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
app.js
var myApp = angular.module('myApp', [
'ngRoute',
'ngMessages',
'myControllers'
]);
myApp.config(['$routeProvider', '$httpProvider',
function($routeProvider, $httpProvider) {
\t $routeProvider.
\t when('/', {
\t \t templateUrl: 'partials/home.html',
\t \t controller: 'HomeCtrl'
\t }).
\t \t when('/login', {
\t \t \t templateUrl: 'partials/login.html',
\t \t \t controller: 'LoginCtrl'
\t \t }).
\t \t when('/register', {
\t \t \t templateUrl: 'partials/register.html',
\t \t \t controller: 'RegisterCtrl'
\t \t }).
\t \t otherwise({
\t \t redirectTo: '/'
\t \t });
\t
\t $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}]);
controllers.js
var myControllers = angular.module('myControllers', []);
myControllers.controller('HomeCtrl', [ '$scope',
function($scope) {
\t \t console.log("HOME");
\t \t //another code
}]);
myControllers.controller('LoginCtrl', [ '$scope',
function($scope) {
\t \t console.log("LOGIN");
\t \t //another code
}]);
myControllers.controller('RegisterCtrl', [ '$scope',
function($scope) {
\t \t console.log("REGISTER");
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-messages.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
Я уверен, что у вас есть ошибка o n line 7 – Manu