1

I have an AngularJS app that currently works with the 1.2.9 angular version, but when I change the library version to 1.3.2, I get the following error:

Argument 'AlumnosController' is not a function, got undefined

view code:

<!DOCTYPE html>
<html ng-app>
<head>
    <meta charset="utf-8">
    <title>Cuaderno Alumnos</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body ng-controller="AlumnosController">
        <h1>Cuaderno Alumnos</h1>   
    <div class="wrapper">
    <div class="contact-item" ng-repeat="alumno in alumnos | orderBy:'nombre'">
        <div class="nombre"> {{alumno.nombre}} - {{alumno.telefono}}</div>
        <span class="curso">{{alumno.curso}} </span>
    </div>
     </div> 
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js" type="text/javascript"></script>
<script src= "AlumnosController.js" type="text/javascript"></script>
</body>

Controller code:

function AlumnosController($scope){
        $scope.alumnos=[
                {nombre:"Juan Blanco", telefono: "1234567890", curso:"Segundo ESO"},
                {nombre:"Rosa Luxemburgo", telefono: "0987654321", curso:"Primero ESO"},
                {nombre:"Alberto Herrera", telefono: "1122334455", curso:"Segundo ESO"},
                {nombre:"Ana Mariño", telefono: "6677889900", curso:"Tercero ESO"}
                ];
        }

Any ideas?

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
  • check this one http://stackoverflow.com/questions/26646941/getting-an-error-when-using-ng-controller-in-angularjs-ver-1-3-0/26647015#26647015 – Kalhan.Toress Nov 17 '14 at 04:38
  • 2
    Global controllers were disabled in 1.3.0 , and please check the link on previous comment – Kalhan.Toress Nov 17 '14 at 04:39
  • possible duplicate of [Controller not a function, got undefined, while defining controllers globally](http://stackoverflow.com/questions/25111831/controller-not-a-function-got-undefined-while-defining-controllers-globally) – PSL Dec 07 '14 at 20:22
  • @K.Toress , Thanks, that solved the problem. – StreetWizard Sep 11 '15 at 21:49

1 Answers1

0

There was a breaking change introduced in Angular 1.3.0-beta-15:

Breaking Changes

$controller: due to 3f2232b5, $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.

To migrate, register your controllers with modules rather than exposing them as globals:

Before:

function MyController() {
  // ...
}

After:

angular.module('myApp', []).controller('MyController', [function() {
  // ...
}]);

Although it's not recommended, you can re-enable the old behavior like this:

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

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265