无法在AngularJS中注册模块

无法在AngularJS中注册模块

问题描述:

我有一个简单的前端应用程序,可以找到here。在我的索引文件我加载app.js先authentication.js服务:无法在AngularJS中注册模块

<script src="scripts/app.js"></script> 
<script src="scripts/services/authentication.js"></script> 

认证模块可以在scripts/services/authentication.js文件中找到,看起来像这样:

'use strict'; 

angular.module('Authentication') 

.factory('AuthenticationService', 
    ['$http', '$rootScope', 
    function ($http, $rootScope) { 
     var service = {}; 

     service.Login = function (username, password) { 
      $http.post('/users/authenticate', { username: username, password: password }) 
       .success(function (response) { 
        console.log(response); 
       }); 
     }; 

     service.SetCredentials = function (token) { 
      $rootScope.localStorage.setItem('token', token);    
      $http.defaults.headers.common['Authorization'] = 'Bearer ' + token; // jshint ignore:line 
     }; 

     service.ClearCredentials = function() { 
      $rootScope.removeItem('toke'); 
      $http.defaults.headers.common.Authorization = 'Bearer '; 
     }; 

     return service; 
}]); 

我非常新AngularJS和我只是遵循这个tutorial。我运行我的应用程序时遇到的问题是:

模块“身份验证”不可用。你要么拼写错误的模块名称或忘了装载它...

+0

我试图在index.html文件中交换app.js和authentication.js,但得到了'Module frontendApp is not available'。我真的很想知道,为什么这样一个基于教程的简单代码不起作用。 – Jacobian

angular.module('Authentication') 

应该

angular.module('app') 

因为你尝试加载在同一文件中的两个模块,但根据这个可能的,即使你的教程在这里提到那种事情不能这样做,将Authentication更改为app

+0

我会在一秒钟内检查它! – Jacobian

+0

它的工作原理!谢谢你,先生! – Jacobian

+0

哦,对不起!谢谢,小姐! – Jacobian