Thomas
Thomas

Reputation: 247

angularjs - can not find the controller

I have 2 js files in different directories for each module. if i start my app, i get the error, that the controller SubAppCtrl cannot be found ... can anyone tell me, why do i get this error message?

Code in mainAPP:

var myModule = angular.module('mainAPP', ['subAPP']); 

myModule.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/test', {templateUrl: 'components/test/test-list.html', controller: SubAppCtrl});}]);

Code in subAPP:

var myapp = angular.module('subAPP', []); 

myapp.controller('SubAppCtrl', ['$scope', '$rootScope', '$translate', function ($scope, $rootScope, $translate){ .... ]);

html

<!doctype html>
<html ng-app="mainAPP" lang="en">
<head>
...
  <script src="lib/angular/angular.js"></script>
  <script src="components/test/subAPP.js"></script>
  <script src="js/mainAPP.js"></script>
...
</head>
<body>

<div ng-view></div>
</body>
</html>

Upvotes: 1

Views: 2373

Answers (1)

akonsu
akonsu

Reputation: 29566

mainApp should read

var myModule = angular.module('mainAPP', ['subAPP']); 

myModule.config([
        /******/ '$routeProvider',
        function ($routeProvider) {
            $routeProvider.when('/test', {
                templateUrl: 'components/test/test-list.html',
                controller: 'SubAppCtrl'
            });
        }
]);

note quotes around the controller name.

Upvotes: 1

Related Questions