1

I have a simple frontend application, which can be found here. In my index file I load app.js first and then authentication.js service:

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

Authentication module can be found in scripts/services/authentication.js file and looks like so:

'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;
}]);

I'm extremely new to AngularJS and I'm just following this tutorial. The problem I get, when I run my application is:

Module 'Authentication' is not available. You either misspelled the module name or forgot to load it...

1
  • I tried to swap app.js and authentication.js in index.html file, but got Module frontendApp is not available. I really wonder, why such a simple code, based on tutorials does not work. Commented Nov 25, 2017 at 17:48

1 Answer 1

3
angular.module('Authentication') 

should be

angular.module('app')

Because you try to load two module in same file but this possible even though according to your tutorial mention here that kind of thing couldn't do so change Authentication to app.

Sign up to request clarification or add additional context in comments.

2 Comments

I will check it in a second!
Oh, sorry! Thank you, miss!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.