本人初学angularjs,在看一本书的《angularjs 权威教程》,第二章有个demo,如下。
这里使用angular版本1.2.29,如果换成1.3.1 会报错。
请问,这是如何造成的呢?应该怎么样调试这个错误呢?
<!doctype html>
<html ng-app>
<head>
<meta charset="utf-8">
<title>Simple App</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.29/angular.min.js"></script>
</head>
<body>
<p ng-controller="MyController">
<h1>Hello {{clock}}</h1>
</p>
<script type="text/javascript">
function MyController($scope, $timeout) {
$scope.clock = new Date();
var updateClock = function() {
$scope.clock = new Date();
};
setInterval(function() {
$scope.$apply(updateClock);
}, 1000);
updateClock();
};
</script>
</body>
</html>
After version 1.3, controllers are no longer found on the window object
$controller will no longer look for controllers on window.
https://github.com/angular/angular.js/blob/master/CHANGELOG.md#breaking-changes-31
The JS Bin
http://jsbin.com/vekixa/edit?html,console,output
If you cannot circumvent the wall, please change the CDN inside the wall
It is recommended that the poster follow up to version 1.4 (version is really important)
Just like this. . Of course you can also write