0

Well, I'm not able to get a controller to work in a simple example which code looks like:

app.js:

(function() {
  'use strict';

    // Define AngularJS application
    var myApp = angular.module('myApp', [
        'ngRoute'
    ]);


    // Set application routes
    myApp.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
        $routeProvider
        .when('/registration', {
            templateUrl: 'views/registration.html',
            controller: 'registrationController'
        }) 
        .otherwise({
            redirectTo: '/'
         });

    }]);    

})();

registration.js:

(function() {
  'use strict';

    myApp.controller('registrationController', [
        '$scope',
        '$routeParams',
        '$rootScope',
        '$location', 
        function(
            $scope, 
            $routeParams, 
            $rootScope, 
            $location
        ){


        }
    ]);

})();

no clue why but it throws an error

registration.js:4 Uncaught ReferenceError: myApp is not defined

3

1 Answer 1

3

In your registration.js

(function() {
'use strict';

angular
.module('myApp').controller('registrationController', [
    '$scope',
    '$routeParams',
    '$rootScope',
    '$location', 
    function(
        $scope, 
        $routeParams, 
        $rootScope, 
        $location
    ){


    }
]);

})();

And the error is pretty much self explanatory. myApp is not defined in registration.js file. That's why you're getting that error

Sign up to request clarification or add additional context in comments.

1 Comment

Well, that did the job. Didn't know that when wrapped in unnamed function will loose previously defined myApp module.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.