AngularJs的新版本1.3.0并不是1.2.9旧版本的工作原理。什么是新版本的新产品?
<html ng-app>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<div ng-controller = "MyController">
<h1>{{author.name}}</h1>
<p>{{ author.title }}</p>
</div>
<script>
function MyController($scope) {
$scope.author = {
'name': 'Nagy Dávid',
'title': 'Demo',
}
}
</script>
</body>
</html>
答案 0 :(得分:11)
角度 v1.3.0-beta.15 存在重大变化,因此默认情况下,angular将不再在窗口中查找控制器。有关详细信息,请参阅3f2232b5。
With the exception of simple demos, it is not helpful to use globals
for controller constructors. This adds a new method to `$controllerProvider`
to re-enable the old behavior, but disables this feature by default.
BREAKING CHANGE:
`$controller` will no longer look for controllers on `window`.
The old behavior of looking on `window` for controllers was originally intended
for use in examples, demos, and toy apps. We found that allowing global controller
functions encouraged poor practices, so we resolved to disable this behavior by
default.
To migrate, register your controllers with modules rather than exposing them
as globals:
因此,为了使您的示例在不创建自己的模块的情况下工作(不推荐),您可以在底部的脚本标记中添加此代码:
angular.module('ng').config(function ($controllerProvider) {
$controllerProvider.allowGlobals();
});
有关工作示例,请参阅下面的一个插件。
示例plunker: http://plnkr.co/edit/xdlfJRpH8lHzNvqyQ0no?p=preview