title: How to define multiple controllers for one view in angularJS?
body: <p>What I tried :</p>
  
  <pre><code> $routeProvider
       .when('/paintings',
           {
               controller: 'imageController' , 'getPaintingImages'
               templateUrl: 'paintings.html'
           })
       .when('/foods',
           {
               controller: 'imageController' , 'getFoodImages'
               templateUrl: 'food.html'
           })
  </code></pre>
  
  <p>I wanted getPaintingImages and getFoodImages to get the list of paintings/foods from a factory, and imageController to manipulate the images. But only first controller gets called.</p>
  
  <p>Earlier I wrote code to get the images in imageController only, </p>
  
  <pre><code>myWebsite.controller('imageController', function imageController($scope, getPaintings){
  
      $scope.images = getPaintings.images();                // but need to make this work for different set of images
      $scope.imageCount = countObjectElements($scope.images);     
      $scope.selectedImage = $scope.images[0];
      $scope.selectedImageIndex = 0;
  
      $scope.updateSelectedImage = function(img) {        
          $scope.selectedImage = img;
          $scope.selectedImageIndex = $scope.images.indexOf(img);     
      };  
      $scope.updateSelectedImageIndex = function(val) {       
  
          alert($scope.imageOf);
          if($scope.selectedImageIndex &lt;= 0)
              $scope.selectedImageIndex = $scope.imageCount;
  
          $scope.selectedImageIndex = ($scope.selectedImageIndex + val) % $scope.imageCount;      
          $scope.selectedImage = $scope.images[$scope.selectedImageIndex];
      };
  });
  </code></pre>
  
  <p>As I am a beginner in angularJS, I am not sure if creating multiple controllers a solution for re-using imageController ? If yes how to do this, if not how to re-use imageController to work for different set of images. In case of functions, re-use of function is generally by parameter passing. But here I am wondering how can a controller take parameters as it gets called for a view internally ?</p>