最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - angular 1.3 can't find the controller function - Stack Overflow

programmeradmin4浏览0评论

I am new to angular and tried to go with 1.3 new release.
Here is my code

<script src=".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] .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=".2.0/angular.min.js"></script>   

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

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.

Share Improve this question edited Nov 4, 2014 at 18:31 Blazemonger 92.9k27 gold badges145 silver badges181 bronze badges asked Sep 5, 2014 at 5:33 DéboraDébora 5,95229 gold badges104 silver badges176 bronze badges 3
  • Try the unminified angular.js file. The error messages are usually easier to understand – Phil Commented Sep 5, 2014 at 5:37
  • @Phil. I tried https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.js . Still same. not working.. – Débora Commented Sep 5, 2014 at 5:42
  • I myself am new to angular. Can you use data attributes for angular directives? Like data-ng-controller instead of ng-controller. Secondly, try a code like this: angular.module('controllers').controller('SimpleController', ['$scope', function($scope) { /* ... */ }]);. Basically, setup the controller in the "angular's namespace" – Gasim Commented Sep 5, 2014 at 5:46
Add a comment  | 

1 Answer 1

Reset to default 24

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();
}]);
发布评论

评论列表(0)

  1. 暂无评论