0

My application involve 2 pages - index.html , details.html . And 2 controllers - homeCtrlr , detailsCtrlr . The code in both of the controller had reached 1000 lines of code and might increase still . It looks like the following :

app.controller('detailsCtrlr',()=>{
 $scope.method_1 = (){}
 $scope.method_2 = (){}
  ...
 $scope.method_n = (){}

});

It becomes more difficult to maintain and debug the code due to its large size . Is there any other way to place those methods as files ?

hhsb
  • 560
  • 3
  • 23
  • 1
    You should try to see if everything in this controller should **really** be in the controller and not in a factory/service/... + Look for redundant code that can be put in an *util* function that can be reuse multiple times + Comment your code and try to separate it in logical block to simplifies the reading – Weedoze Sep 20 '17 at 07:26
  • 1
    try to look at this existing stackOverflow [solution](https://stackoverflow.com/questions/25819661/how-to-split-single-controller-in-multiple-js-files-in-angularjs), this may helpful. – Immanuel Kirubaharan Sep 20 '17 at 07:28
  • @Weedoze I did that already, thanks anyway . – hhsb Sep 20 '17 at 07:33
  • @ImmanuelKirubaharanS I think that might just do . – hhsb Sep 20 '17 at 07:33

1 Answers1

0

Up to me.

if you are using the backend api integration in controller for accessing the data from backend, then you must to create the angular services,factories etc. because it is better place to write the code and it also remove the separation of concern.

in controller part:

you just create the service object and call the service method and handle data accordingly.

in service part:

make an method for api calling or getting data from serve.

so i think, this can be remove your massive code instead of writtng at one place.

Enjoy coding.

Kunvar Singh
  • 1,779
  • 2
  • 13
  • 21