简体   繁体   English

角度1.3找不到控制器功能

[英]angular 1.3 can't find the controller function

I am new to angular and tried to go with 1.3 new release. 我是棱角分明的新手并尝试使用1.3新版本。
Here is my code 这是我的代码

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
</head>
<body>
<div data-ng-controller="SimpleController"  >

<ul>        
<li data-ng-repeat="customer in customers">{{customer.name}} - {{customer.city}}</li>
</ul>


</div>
<script>

function SimpleController($scope){

    alert('done1');
    $scope.customers=[{name:'1name',city:'1city'},{name:'2name',city:'2city'}];
    alert('done');
} 
</script>

The console gives this error. 控制台出现此错误。

Error: [ng:areq] http://errors.angularjs.org/1.3.0-rc.0/ng/areq?p0=SimpleController&p1=not%20a%20function%2C%20got%20undefined    

But when I change the angular source to 但是当我改变角度源时

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>   

Then it works. 然后它工作。 I use chrome. 我用铬。 any one let me know where can be the problem exists. 任何人都让我知道问题存在于哪里。

Global controller functions are no longer supported by default in 1.3. 1.3中默认不再支持全局控制器功能。 See change log ... 查看更改日志 ...

$controller will no longer look for controllers on window. $ controller将不再在窗口中查找控制器。 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. 我们发现允许全局控制器功能鼓励不良做法,因此我们决定默认禁用此行为。

It can be re-enabled with this config... 可以使用此配置重新启用它...

angular.module('myModule').config(['$controllerProvider', function($controllerProvider) {
  // this option might be handy for migrating old apps, but please don't use it
  // in new ones!
  $controllerProvider.allowGlobals();
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM