Angular controller error: 'Controller is not a function, got undefined'

Angular controller error: 'Controller is not a function, got undefined'

我的 angular 应用程序出现以下错误: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 我遇到了同样的问题。

我的 JS:

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

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

这是我的 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>

导致此错误的原因是什么?我计划使用 $stateProvider$urlRouterProvider,但首先尝试使用内联 ng-controller 属性的这个简单示例并遇到此错误。我认为我使用了正确的语法,但如果我错了请纠正我。

非常感谢您抽出宝贵时间。如果您需要任何其他信息或者我不清楚,请告诉我。

将您的代码更新为

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

controller() 本身就是一个被调用的函数,而不是一个 属性 被分配的函数。

试试这个:

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

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

正确的代码应该是:

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

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

Working Fiddle