title: Where should I write general purpose controller function in angular.js?
body: <p>I am writing some functions for check/uncheck all for table list and it is working fine,</p>
  
  <p>Controller is,</p>
  
  <pre><code>    invoiceApp.controller('itemController', ['$scope', 'itemService', '$route', function ($scope, itemService, $route) {
  $scope.checkAllItem;
          $scope.listItem = {
              selected: []
          };
          $scope.checkUncheck = function () {
              if ($scope.checkAllItem) {
                  $scope.listItem.selected = $scope.items.map(function (item) {
                      return item.id;
                  });
              } else {
                  $scope.listItem.selected = [];
              }
          };
  </code></pre>
  
  <p>HTML TABLE,</p>
  
  <pre><code>   &lt;table id="dt_basic" class="table table-bordered table-hover" width="100%"&gt;
                      &lt;thead&gt;                         
                          &lt;tr&gt;
                              &lt;th class="text-center" width="5%"&gt;
                                  &lt;input type="checkbox" name="checkbox-inline" ng-model="checkAllItem" ng-click="checkUncheck()"&gt;
                                  &lt;input type="checkbox" name="checkbox-inline" ng-click="uncheckAll()"&gt;
                              &lt;/th&gt;
                              &lt;th width="15%" ng-click="sort()"&gt;Name&lt;a href="javascript:void(0)"&gt;&lt;i class="fa fa-sort small"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/th&gt;
                              &lt;th width="65%"&gt;Description&lt;/th&gt;
                              &lt;th width="5%"&gt;Unit&lt;/th&gt;
                              &lt;th width="10%"&gt;Rate&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          &lt;tr ng-repeat="item in items" data-toggle="modal" data-target="#itemModel" ng-click="getItem(item.id)" style="cursor: pointer"&gt; 
                              &lt;td class="text-center"&gt;
                                  &lt;input type="checkbox" checklist-model="listItem.selected" checklist-value="item.id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;&lt;a&gt;{{item.name}}&lt;/a&gt;&lt;/td&gt;
                              &lt;td&gt;{{item.description}}&lt;/td&gt;
                              &lt;td&gt;{{item.unit}}&lt;/td&gt;
                              &lt;td&gt;{{item.rate}}&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
  </code></pre>
  
  <p>It is working fine,Here my problem is,In my project I have many tables in different pages,I have to copy past this same code (Talking about Controller only ) to everywhere.Is there any method to write it generally? </p>
  
  <p>I tried with <code>$routescope</code>,
  but It is not working with <code>ng-model</code>,Is there any method to implement the same?</p>