In AngularJS application can we have multiple services files

261 Views Asked by At

In AngularJS application, for one module say "login" functionality can we create multiple services files like logincheck-svc.js and logingo-svc.js And reference both the files in login-ctrl.js file I am asking this question because the services files are becoming large in terms of LOC and Plato report is showing very low maintainability index[due to the complexity in the file]

2

There are 2 best solutions below

0
On

As far isolation of concerns you can have as much dependences on your controller as you wish.

angular.module('app.controllers').controller('OneController', [
  '$scope',
  'OneService',
  'TwoServices',
  'ThreeServices',
  function ($scope, OneService, TwoServices, ThreeServices) {...}]);
0
On

Of course you can, I would even say it is a very good idea from the moment your files become voluminous. :-)

"Divide and conquer"