大家好,我是一个有点角色的人。我开始使用此演示Angular Js Tutorial制作应用程序。我面临的问题是我无法弄清楚如何解决我所得到的错误。我尝试过一堆解决方案,但没有一个能为我工作。这是我得到的错误
myapp.html:13 Uncaught ReferenceError: HelloController is not defined(anonymous function)
angular.js:13550 Error: [ng:areq] http://errors.angularjs.org/1.5.5/ng/areq?p0=HelloController&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:6:412
at qb (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:23:157)
at Pa (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:23:244)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:89:77
at O (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:72:75)
at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:64:7)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:58:305)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:58:322)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:57:455(anonymous function) @ angular.js:13550(anonymous function) @ angular.js:10225n.$apply @ angular.js:17334(anonymous function) @ angular.js:1749invoke @ angular.js:4665c @ angular.js:1747yc @ angular.js:1767ee @ angular.js:1652(anonymous function) @ angular.js:30863b @ angular.js:3166Qf @ angular.js:3456Pf.d
这是我的代码。
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
</head>
<body ng-app>
<div ng-controller="HelloController">
<h2>Welcome {{helloTo.title}} to angular</h2>
</div>
<script>
var myapp = angular.module("myapp" , [])
.controller(HelloController , function($scope){
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
});
</script>
</body>
</html>
请告诉我,我做错了什么
答案 0 :(得分:1)
您错过了控制器名称周围的引号,因为角度解析器将其视为另一个在您的页面/代码中找不到的变量。
var myapp = angular.module("myapp" , [])
.controller('HelloController' , function($scope){
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
});
答案 1 :(得分:1)
为此您需要按照以下方式进行更改
<body ng-app="myapp">
<div ng-controller="HelloController">
<h2>Welcome {{helloTo.title}} to angular</h2>
</div>
<script>
var myapp = angular.module("myapp", [])
.controller("HelloController", function ($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
});
</script>
</body>
你缺少在HelloController中分配模块名称和字符串引用。