我做错了什么?我试着用use book写一个简单的例子,但是我得到了错误。在这个例子中需要修复什么才能使其工作?
这里还写了什么?
<html>
<head>
<title>page 29</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta charset="utf-8">
<script
type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.min.js">
</script>
<script>
var Ctrl = function ($scope) {
$scope.getName = function() {
return $scope.name
}
}
</script>
<body ng-app>
<div ng-controller="Ctrl">
Напиши свои мысли о ангуляре
<input type="text" ng-model="name">
<h1> angularjs - {{getName()}} </h1>
<p>
</p>
</div>
</body>
</head>
</html>
在控制台我看到错误:
Error: [$controller:ctrlreg]
http://errors.angularjs.org/1.8.3/$controller/ctrlreg?p0=Ctrl
at angular.js:99:1
at angular.js:11787:17
at ea (angular.js:10818:34)
at p (angular.js:10603:32)
at g (angular.js:9942:13)
at g (angular.js:9945:13)
at angular.js:9807:30
at angular.js:1968:11
at m.$eval (angular.js:19523:16)
at m.$apply (angular.js:19622:20)
解决方案-第一个示例:
<html>
<head>
<title>page 29</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta charset="utf-8">
<script
type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.min.js">
</script>
<script>
var myApp = angular.module('myApp',[]);
myApp.controller('Ctrl', ['$scope', function($scope) {
//var Ctrl = function ($scope) {
$scope.getName = function() {
return $scope.name
}
}]
)
</script>
<body ng-app="myApp">
<div ng-controller="Ctrl">
Напиши свои мысли о ангуляре
<input type="text" ng-model="name">
<h1> angularjs - {{getName()}} </h1>
<p>
</p>
</div>
</body>
</head>
</html>