错误: [ng:areq] 客户控制器不是未定义的函数
Error: [ng:areq] customerController not a function got undefined
我是angularjs的初学者,我正在编写一个简单的应用程序来开始使用它。我一直收到此错误Error: [ng:areq] customerController not a function got undefined
我试图检查我的代码有什么问题,一切似乎都很好(至少对我来说)。请浏览代码并帮助我
首页.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>
应用.js
(function(){
var app = angular.module('customerApp', []);
})();
客户控制器.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:我已经提到了这个问题
您忘了关闭脚本标签的开头部分。在问题代码中的语法突出显示中很明显
改变
<script src="/app/controllers/customerController.js"</script>
自
<script src="/app/controllers/customerController.js"></script>
不能再将全局函数用作控制器。
JavaScript/Angular(Live Preview http://codepen.io/larryjoelane/pen/ZQqVVY):
var app = angular.module("customerApp", []);
app.controller("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;
};
});
.HTML:
<body ng-app="customerApp" 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 }}
相关文章:
- Jquery未定义函数正在停止其他操作
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- jQuery文件上传和验证未定义函数
- 引用错误:未定义函数-Firefox
- res.render中出错,未定义函数
- 神秘的未定义函数
- 尝试使用函数和Ajax修改值时未定义函数
- 引用错误:未定义函数
- ReferenceError:未定义函数
- 在 Angular JS 中使用 ng-include 的未定义函数
- 未捕获的引用错误:未定义函数
- j查询工具提示引发错误:未定义函数
- 未捕获的引用错误: 未定义单击世界 -- 未定义函数
- JS:引用错误:未定义函数
- 茉莉花未定义函数
- Javascript 错误:未捕获的引用错误:未定义 [函数]
- 未定义函数
- 尽管 js 文件引用在标头中,但未定义函数
- Javascript 未定义函数错误