Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument is not aNaNunction, got undefined

Tags:

angularjs

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>
like image 416
Craig Avatar asked Nov 10 '14 00:11

Craig


1 Answers

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

like image 195
Explosion Pills Avatar answered Oct 14 '22 21:10

Explosion Pills