我是 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/