javascript - 错误 : [ng:areq] customerController not a function got undefined

标签 javascript angularjs angularjs-controller

我是 angularjs 的初学者,我正在编写一个简单的应用程序来开始使用它。我不断收到此错误 Error: [ng:areq] customerController not a function got undefined

我已经尝试检查我的代码有什么问题,一切似乎都很好(至少对我而言)。请仔细检查代码并帮助我

Home.html

<html ng-app="customerApp">
<head>
<title> MyProject</title>
</head>

<body ng-controller="customerController">
<table border="2">
    <thead>
        <th ng-click="doSort('name')">Name</th>
        <th ng-click="doSort('city')">City</th>
    </thead>
    <tr ng-repeat="cust in customers | filter: customerFilter | orderBy:sortBy:reverse">
        <td>{{ cust.name }}</td>
        <td>{{ cust.city }}</td>
    </tr>
</table>
<br \>
<br \>
    Total customers: {{ customers.length }}

<script src="/scripts/angular.min.js"></script>
<script src="/app/app.js"></script>
<script src="/app/controllers/customerController.js"</script>
</body>
</html>

app.js

(function(){
    var app = angular.module('customerApp', []);
})();

customerController.js

(function (){

    var customerController = function ($scope){
        $scope.sortBy='name';
        $scope.reverse=false;

    $scope.customers= [{name:'Sachin',city:'Dharwad'},    {name:'Karan',city:'Hubli'},{name:'Shishir',city:'Mysore'}];
    $scope.doSort= function (propName){

        $scope.sortBy= propName;
        $scope.reverse= !$scope.reverse;
    };
};
    customerController.$inject = ['$scope'];
    angular.module('customerApp').controller('customerController',customerController    );
})();

PS:我已经提到了this question

最佳答案

您忘记关闭脚本标签的开头部分。在问题代码中的语法高亮中很明显

改变

<script src="/app/controllers/customerController.js"</script>

<script src="/app/controllers/customerController.js"></script>

关于javascript - 错误 : [ng:areq] customerController not a function got undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254561/

相关文章:

javascript - ngFor 没有显示 html 中的项目? Angular 2/4

angularjs - 当 Angular 完成向 DOM 添加范围更新时,如何触发方法?

javascript - Angular 递归方法不返回值

javascript - 定义作用域变量的最佳实践

javascript - D3 时区偏移量移至前一天

javascript - 如何删除draw2d.js中的连接?

javascript - Chrome 扩展在加载同步数据后运行 Angular

angularjs - 基于 Controller bool 变量显示/隐藏元素AngularJS

javascript - 如何组织和减少 AngularJS Controller 的大小?

一旦文本值输入发生变化,JavaScript onchange 就会更新变量