Craig
Craig

Reputation: 2143

Argument is not aNaNunction, got undefined

I'm migrating from AngularJS 1.2.26 to 1.3.2 and receive an Error

Not the best error message to work out but it looks like it is saying that my controller is not defined? Can I no longer define controllers this way?

Error: error:areq

Bad Argument

Argument 'welcomeController' is not aNaNunction, got undefined

My index page is something like:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-sanitize.min.js"></script>

var myApp = angular.module('kioskApp', ['ngRoute','ngSanitize']).run(function($rootScope, $location, $timeout) {
    $rootScope.authenticated = true;
});

myApp.config(function($routeProvider, $locationProvider, $sceDelegateProvider) {
    $routeProvider
    .when('/welcome', {
        templateUrl : 'pages/welcome.php',
        controller  : 'welcomeController'
    });
});

function welcomeController($rootScope, $scope, $http, $location) {
    //stuff
}

My welcome page is something like:

<div ontouchmove="preventDrag(event)" ng-show="authenticated">
    <!-- some images -->
</div>

Upvotes: 6

Views: 6588

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

You could use controller: welcomeController (without the quotes) to use it as a function. Otherwise, do something like myApp.controller('welcomeController', welcomeController).

You should also learn the syntax for dependency injection

Upvotes: 3

Related Questions