1

I have the following three angularjs scripts:

/config.js
/authentication/LoginCtrl.js
/authentication/loginFactoyr.js

App ristoreApp is defined in config.js.

//config.js

angular.module('ristoreApp', ['ngRoute'])

.config(function ($routeProvider, $locationProvider, $httpProvider) {
//  $httpProvider.responseInterceptors.push('httpInterceptor');

    $routeProvider
        .when('/login', { 
            templateUrl: 'authentication/login.html', 
            controller: 'LoginCtrl' 
        })
        .when('/home', { 
            templateUrl: 'home.html', 
        })
        .otherwise({ 
            redirectTo: '/login' 
        });

    $locationProvider.html5Mode(true);
});

My controller calls the app by "angular.module":

angular.module('ristoreApp', [])
.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){
    $scope.authenticate = function() {
        loginFactory.login($scope.username, $scope.password)
        .then(function(response) {
            console.log(response);
            $location.path('/home');
        }, function errorCallBack(response) {
            console.log(response);
            $location.path('login');
        });
    }
}]);

Got the error "Error: ng:areq Bad Argument"

Argument 'LoginCtrl' is not a function, got undefined

Why does it say my controller is not a function? What did I do wrong?

1 Answer 1

1

Try this. Remove the quotes on LoginCtrl.

controller: LoginCtrl

Then, define the controller as:

var LoginCtrl = app.controller("LoginCtrl", ["$scope", function($scope) { /* etc... */}]);
Sign up to request clarification or add additional context in comments.

2 Comments

What quotes do I remove? I changed my controller to app = angular.module('ristoreApp', []); var LoginCtrol = app.controller("LoginCtrl", ['$scope',... but it didn't help
You have to remove the quotes. controller: 'LoginCtrl' should be controller: LoginCtrl

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.