Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im new in AngularJS and im trying to create an authentication service but I'm getting this error.

Error: [$injector:modulerr] Failed to instantiate module flujoDeCaja due to:
[$injector:modulerr] Failed to instantiate module auth due to:
[$injector:nomod] Module 'auth' 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.

Here is my code:

Service.js

'use strict';

var mod = angular.module('auth',['restangular']);

mod.service('AuthService', ['', function(){

    var userIsAuthenticated = false;

    this.setUserAuthenticated = function(value){
        userIsAuthenticated = value;
    };

    this.getUserAuthenticated = function(){
        return userIsAuthenticated;
    });

}]);

App.js

var angularModule = angular.module('flujoDeCaja', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute',
  'restangular',
  'auth'
]);

Index.html

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/restangular/dist/restangular.js"></script>
<script src="scripts/services/services.js"></script>
<script src="scripts/app.js"></script>

What I'm doing wrong?

Thank you in advance :)

share|improve this question
    
don't need a blank string for the dependencies if you have none for the service definition –  shaunhusain Mar 11 at 21:28

1 Answer 1

up vote 0 down vote accepted

Corrected the bit I believe is wrong.

mod.service('AuthService', [function(){

    var userIsAuthenticated = false;

    this.setUserAuthenticated = function(value){
        userIsAuthenticated = value;
    };

    this.getUserAuthenticated = function(){
        return userIsAuthenticated;
    };

}]);
share|improve this answer
    
Thank you, you are right. My other mistake was that ')' after getUserAuthenticated function's '}' –  Rodrigo Cifuentes Gómez Mar 11 at 22:02
    
cool thanks for the feedback, updated my answer to reflect the changes needed to fix it all –  shaunhusain Mar 12 at 17:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.