0

I'd started to create small app and now it becomes more huge and huge each new day.

I need to divide 1 controller to some files?

I have this now:

angular.module('myApp.controllers', [])
  .controller('Ctrl1', ['$scope', '$http', function($scope, $http) { 
    // some logic

    $scope.fooBar1 = function() {};
    // some more foo's
    $scope.fooBarN = function() {};

    $scope.booBar1 = function() {};
    $scope.booBar2 = function() {};
    // ......
    $scope.booBarN = function() {};

    $scope.mooBar1 = function() {};
    /* etc */
  }])

Also, I have html file, where I use this controller Ctrl1.

So, I have 1 controller, 1 html and some "parts" in it. Each part contain some logic and some foo's. Now, I think, it is better to put boo part to boo.js, foo part to foo.js, moo to moo.js etc.

I need: 1 controller divided on some files (with same $scope) to divide hard logic, 1 html file, where I will use scope from all of these files.

Also, I found this: How to create separate AngularJS controller files?. In answer to this question some says how to separate some controllers to some files, I don't need this, so I need another solution.

Community
  • 1
  • 1
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
  • You may find this helpful - it's supposed to discuss how to share data among controllers. If you can break up controllers by function, then share data between them, that should help you break up and organize your code. https://egghead.io/lessons/angularjs-sharing-data-between-controllers – Surreal Dreams Oct 07 '14 at 16:28

1 Answers1

1

Check out Todd Motto's style guide. It is an excellent resource on how to best structure angular projects. Pick and choose what you find helpful to your own workflow. It will likely also be helpful for you to better understand how services can be used to share data throughout apps, and why it's important to keep controllers thin and generally sans logic.

Duncan
  • 2,550
  • 2
  • 17
  • 18