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

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

问题描述

我是 Angular 的新手,并尝试使用 1.3 新版本.
这是我的代码

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script><身体><div data-ng-controller="SimpleController" ><ul><li data-ng-repeat="customer in customers">{{customer.name}} - {{customer.city}}</li>

<脚本>函数 SimpleController($scope){警报('完成1');$scope.customers=[{name:'1name',city:'1city'},{name:'2name',city:'2city'}];警报('完成');}

控制台给出了这个错误.

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

但是当我将角度源更改为

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

然后就可以了.我用铬.任何人都可以告诉我问题出在哪里.

解决方案

1.3 中不再默认支持全局控制器功能.请参阅更改日志...

<块引用>

$controller 将不再在窗口上寻找控制器.老人在窗口上查看控制器的行为最初是打算的用于示例、演示和玩具应用程序.我们发现允许全局控制器功能鼓励不良做法,因此我们解决了默认情况下禁用此行为.

可以使用此配置重新启用...

angular.module('myModule').config(['$controllerProvider', function($controllerProvider) {//此选项对于迁移旧应用程序可能很方便,但请不要使用它//在新的!$controllerProvider.allowGlobals();}]);

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>   

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

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

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