0

I am getting the following error in my angular application: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined. My JS and HTML are below. This is actually a part of an ionic/cordova project, but here is a simplified jsfiddle in which I encounter the same problem.

My JS:

var app = angular.module('TourneyTime', ['ionic']);

app.controller = ('HomeController', function($scope) {
     $scope.players = "testing";
});

And here is my HTML:

<html ng-app="TourneyTime">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World!</title>

    <link href="bower_components/ionic/lib/css/ionic.css" rel="stylesheet">
    <link href="css/app.css" rel="stylesheet">
    <script src="bower_components/ionic/lib/js/ionic.bundle.js"></script>
    <script src="js/app.js"></script>

</head>
<body ng-controller="HomeController">
    <div class="app">
        <h1>Apache Cordova</h1>
        <h1>{{players}}</h1>

    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script src="bower_components/jquery/dist/jquery-2.1.4.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

What is causing this error? I was planning on using $stateProvider and $urlRouterProvider but tried this simple example with an in-line ng-controller attribute first and encountered this error. I think I'm using the correct syntax but please correct me if I am wrong.

Thank you very much for your time. Let me know if you need any additional information or if I am being unclear.

3 Answers 3

3

controller() is itself a function to be called, not a property to be assigned as you're doing.

Try this instead:

var app = angular.module('TourneyTime', ['ionic']);

app.controller('HomeController', function($scope) {
    $scope.players = "testing";
});
Sign up to request clarification or add additional context in comments.

Comments

1

Update your code to

app.controller('HomeController', function($scope) {
     $scope.players = "testing";
});

Comments

1

Correct code should be:

var app = angular.module('TourneyTime', ['ionic']);

app.controller('HomeController', function($scope){
  //code
});

Working Fiddle

1 Comment

why you removed ionic module?

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.