angularjs Error: [ng:areq] Argument 'PhoneListCtrl' is not a function, got undef,该怎么处理
angularjs Error: [ng:areq] Argument 'PhoneListCtrl' is not a function, got undef
以下代码返回错误
Error: [ng:areq] Argument 'PhoneListCtrl' is not a function, got undefined
请问大家是什么原因?
------解决思路----------------------
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>
------解决思路----------------------
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进行声明了。
以下代码返回错误
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>
------解决思路----------------------
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>
------解决思路----------------------
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进行声明了。