Thursday, September 11, 2014

AngularJS, allowGlobals for global controllers

Starting v1.3+ using global controllers without allowGlobals() set, will generate a:

"Error: [ng:areq] Argument 'MyController' is not a function, got undefined"

see plnkr = http://plnkr.co/edit/K2RiP2t3OK4apO2cx82Y?p=preview
 <!DOCTYPE html>  
 <html ng-app>  
  <head>  
   <link rel="stylesheet" href="style.css">  
   <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.js"></script>  
   <script type="text/javascript">  
    angular.module("ng").config(function($controllerProvider){  
        $controllerProvider.allowGlobals();  
    });  
    function MyController() {}  
   </script>  
  </head>  
  <body>  
   <div ng-controller="MyController"></div>  
  </body>  
 </html>