Arianule Arianule - 1 year ago 94
AngularJS Question

Separating controllers inside Ionic app

Is it better to have all controllers inside one file(example controllers.js)

angular.module('starter.controllers', []).controller('AppCtrl', function($scope){



or is it better to separate these controllers in different files.

Does this affect performance in any way?

Answer Source

It's better to separate controllers. You can get reference to your module be calling module function without dependencies:

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

angular.module('starter.controllers').controller('AppCtrl',   ['$scope', function($scope){


angular.module('starter.controllers').controller('AppCtr2',   ['$scope', function($scope){


If there is a performance impact it is not noticeable. If you would like to have single file in production you can use some tool to combine and minify your code. Also it is better to use array style for dependency injection in your controllers.