angularjs Error: [ng:areq] Argument 'PhoneListCtrl' is not a function, got undef

beysion 2015-03-10 05:59:54
以下代码返回错误
Error: [ng:areq] Argument 'PhoneListCtrl' is not a function, got undefined
请问大家是什么原因?

<!doctype html>
<html ng-app>
<head>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript">
function PhoneListCtrl($scope) {
$scope.phones = [
{"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S."},
{"name": "Motorola XOOM with Wi-Fi",
"snippet": "The Next, Next Generation tablet."},
{"name": "MOTOROLA XOOM",
"snippet": "The Next, Next Generation tablet."}
];
}
</script>
</head>
<body ng-controller="PhoneListCtrl">
<ul>
<li ng-repeat="phone in phones">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
</body>
</html>
...全文
4455 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ibookvip 2016-04-10
  • 打赏
  • 举报
回复
楼主 怎么解决的,请教!!!!
1094740701 2015-09-06
  • 打赏
  • 举报
回复
我使用php的时候也遇到了同样的问题!好郁闷
虎三儿 2015-07-23
  • 打赏
  • 举报
回复
兄台,我从网上拔下来一个页面,最初是由于页面乱码问题,于是添加了char-set,之后就出现了楼主描述的问题。最后我将页面重新复制一分到记事本中,同时将ng-controller重新写一遍,问题解决;我将楼主的代码粘贴下来,运行正常,因此,初步断定不是程序的问题,是个人电脑环境的问题或者编码的问题。
sxhqmcs 2015-03-16
  • 打赏
  • 举报
回复
引用 3 楼 sxhqmcs 的回复:
angular.module('ngApp', []).controller('PhoneListCtrl', function ($scope) { $scope.phones = [ {"name": "Nexus S", "snippet": "Fast just got faster with Nexus S."}, {"name": "Motorola XOOM™ with Wi-Fi", "snippet": "The Next, Next Generation tablet."}, {"name": "MOTOROLA XOOM™", "snippet": "The Next, Next Generation tablet."} ]; } );
不能直接使用function xxx进行声明了。
sxhqmcs 2015-03-16
  • 打赏
  • 举报
回复
angular.module('ngApp', []).controller('PhoneListCtrl', function ($scope) { $scope.phones = [ {"name": "Nexus S", "snippet": "Fast just got faster with Nexus S."}, {"name": "Motorola XOOM™ with Wi-Fi", "snippet": "The Next, Next Generation tablet."}, {"name": "MOTOROLA XOOM™", "snippet": "The Next, Next Generation tablet."} ]; } );
qq_26227523 2015-03-12
  • 打赏
  • 举报
回复
好多人遇到这个问题, 对于非web服务,采用1.08版本的就可以使用,1.3.14版本有问题。 如使用了spring mvc,采用resources映射后,没有版本问题,如jsp中使用 也要 1.0.8版本没有问题,具体原因不知。 期待其他人解决。
zebro1573 2015-03-11
  • 打赏
  • 举报
回复
1、请确定引入了angular.js文件 2、如果引入了,把body 加上ng-app="" <body ng-app="" ng-controller="PhoneListCtrl"> <ul> <li ng-app="" ng-repeat="phone in phones"> {{phone.name}} <p>{{phone.snippet}}</p> </li> </ul> </body>

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧