本文介绍了为什么我的角度控制器未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在下面的教程,教科书向我保证,这个作品,但它与
轰炸Why? I have linted it, been up and down it and I cannot see a problem. Why is SimpleController
coming up undefined?
<html ng-app>
<head>
<title>
</title>
</head>
<body>
<input type="text" ng-model="blah" />
<div ng-controller="SimpleController">
<h3>looping a data set</h3>
<ul>
<li ng-repeat="cust in customers | filter:blah | orderBy:'city'">
{{cust.name | uppercase}} - {{cust.city | lowercase}}
</li>
</ul>
</div>
<script src="angular.js"></script>
<script>
function SimpleController($scope)
{
$scope.customers = [
{name: 'John Smith', city: 'Phoenix'},
{name: 'Jane Smith', city: 'Pittsburgh'},
{name: 'John Doe', city: 'New York'},
{name: 'Jane Doe', city: 'Los Angeles'}
];
}
</script>
</body>
</html>
解决方案
My guess is that the angular.js version you are using is 1.3.0-beta.15
or newer.
There is a breaking change in 1.3.0-beta.15
so that: angular will no longer look for controllers on window
by default. See 3f2232b5 fore more detail:
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:
Therefore, your code should be working fine like the textbook assures for angular.js version older than 1.3.0-beta.15
.
这篇关于为什么我的角度控制器未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!