Controllers in seperate files in Ionic and include order

I started to write an Ionic application and started to write my views and controllers. I want to use a tab-layout.

For clarity i want to seperate my controllers in different files.

My controllers-Folder:

  • controller.js
  • main.js
  • tabs.js

controller.js contains:

angular.module('myApp.controllers', []);

main.js contains:

angular.module('myApp.controllers', ['myApp.services','ionic'])
  .controller('MainCtrl', function ($scope) {
    $scope.name = "Test";
  });

tabs.js contains:

angular.module('myApp.controllers', ['myApp.services','ionic'])
  .controller('TabsCtrl', function ($scope) {

  });

In the app.js i specify my routings:

.state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'app/templates/tabs.html',
    controller: 'TabsCtrl'
  })


  .state('tab.main', {
    url: '/main',
    views: {
      'tab-main': {
        templateUrl: 'app/templates/main.html',
        controller: 'MainCtrl'
      }
    }
  })

And finally in my index.html i include all used files in the header:

    <script src="app/app.js"></script>
    <!-- Controller-Definition -->
    <script src="app/controller/controller.js"></script>
    <script src="app/controller/tabs.js"></script>
    <script src="app/controller/main.js"></script>

My problem is that in the browser i get the error:

Argument 'TabsCtrl' is not a function, got undefined

and i don't know why its not working!

when i change the order of the tabs.js und main.js in the index.html file i get:

Argument 'MainCtrl' is not a function, got undefined

Could someone give me help on this problem? it's probably is something small and simple but i don't get it :-)

You overwrite 'myApp.controllers' module in each file. Try this: controller.js:

angular.module('myApp.controllers', ['myApp.services','ionic']);

main.js:

angular.module('myApp.controllers')
  .controller('MainCtrl', function ($scope) {
    $scope.name = "Test";
  });

tabs.js

angular.module('myApp.controllers')
  .controller('TabsCtrl', function ($scope) {

  });