1

In my angular project I receive the error:

angular.js:13424 Error: [ng:areq] Argument 'homeController' is not a function, got undefined
http://errors.angularjs.org/1.5.3/ng/areq?p0=homeController&p1=not%20aNaNunction%2C%20got%20undefined
    at http://socket.dev/bower_components/angular/angular.js:68:12
    at assertArg (http://socket.dev/bower_components/angular/angular.js:1844:11)
    at assertArgFn (http://socket.dev/bower_components/angular/angular.js:1854:3)
    at $controller (http://socket.dev/bower_components/angular/angular.js:10003:9)
    at link (http://socket.dev/bower_components/angular-route/angular-route.js:1007:26)
    at invokeLinkFn (http://socket.dev/bower_components/angular/angular.js:9623:9)
    at nodeLinkFn (http://socket.dev/bower_components/angular/angular.js:9022:11)
    at compositeLinkFn (http://socket.dev/bower_components/angular/angular.js:8333:13)
    at publicLinkFn (http://socket.dev/bower_components/angular/angular.js:8213:30)
    at lazyCompilation (http://socket.dev/bower_components/angular/angular.js:8551:25)

index.html

<!DOCTYPE html>
<html ng-app="pollApp">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="/bower_components/angular/angular.js"></script>
    <script src="/bower_components/angular-route/angular-route.js"></script>
    <script src="/angular/app.js"></script>
    <script src="/angular/routes.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="/bower_components/bootstrap-css/js/bootstrap.min.js"></script>
    <link href="/bower_components/bootstrap-css/css/bootstrap.min.css" rel="stylesheet">
    <title>Poll</title>

</head>
<body>

<div>
    <div ng-view></div>
</div>

</body>
</html>

app.js

(function () {
    angular.module('pollApp', ['ngRoute']);
})();

homeController.js

(function()
{
    angular.module('pollApp').controller('homeController', homeController);

    function homeController()
    {

        var vm = this;
        vm.fields = 10;
        vm.creater = {};
        vm.participans = {};

        vm.test = function()
        {
            return 'gelukt!';
        }
    }
})();

What could be wrong here?

1
  • 4
    You don't have homeController.js in your index Commented Apr 7, 2016 at 8:19

2 Answers 2

1

Put function homeController() {...} above angular.module('pollApp').controller('homeController', homeController);

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

Comments

0

Why not just define an anonymous function as you won't need to reuse it anywhere.

angular.module('pollApp').controller('homeController', function(){
    //controller content goes here 
});

Comments

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.