角1.3找不到控制器功能 [英] angular 1.3 can't find the controller function

查看:175
本文介绍了角1.3找不到控制器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的角,并试图去与1.3新版本。结果
这里是我的code

I am new to angular and tried to go with 1.3 new release.
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>   

然后,它的工作原理。我使用Chrome。
任何一个让我知道可能是存在问题。

Then it works. I use chrome. any one let me know where can be the problem exists.

推荐答案

全局控制器的功能不再默认情况下,在1.3的支持。请参见更改日志 ...

Global controller functions are no longer supported by default in 1.3. See change log...

$控制器将不再寻求在窗口控制器。老人
  寻找在窗口控制器的行为本来是打算
  为例子,演示和玩具应用的使用。我们发现,让
  全局控制器功能,鼓励他们的不良做法,所以我们决定
  在默认情况下禁用此行为。

$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.

可以重新启用这个配置......

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();
}]);

这篇关于角1.3找不到控制器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆