0

I have a question related to bulk code on a AngularJs controller I have a controller name with userDashboard.js and I have lots of methods api calling for data for example:

1) Charts - Chart 1 ,Chart 2 Chart 3 ... etc.

2) Table - Table 1, 2 etc...

3) Section - 1 , 2 , 3 ..

I want to make separate Js file with same controller to make code readable and understandably how can i achieve this.

Is it is working if i am using same controller name for the other file like:

controller1.js

use strict';
angular.module('onepgr')
  .controller('userDashboard',
  function ($scope,$routeParams, MyAppService,Excel,$timeout) {
   //API
   //Chart
  });

controller2.js

use strict';
    angular.module('onepgr')
      .controller('userDashboard',
      function ($scope,$routeParams, MyAppService,Excel,$timeout) {
      //Table function
      //API
      });
Anil Yadav
  • 1,086
  • 7
  • 18

2 Answers2

1

Do not duplicate controller, make new one, for common things create service/factory which will be injected to each controller and keep common business logic there.

Opal
  • 81,889
  • 28
  • 189
  • 210
hanskoff
  • 182
  • 13
0

This is largely a matter of taste. Check Sajan Mullappallys comment.

Otherwise, johnpapa has a pretty nice guideline which is endorsed by the Angular team. https://github.com/johnpapa/angular-styleguide

See if that suits you are your team mates. You are the ones you have to live with the code, so it's you who have to decide what's good and what's not, for you.

qwelyt
  • 776
  • 9
  • 23