Although all scope functions can be put directly next to $scope after the dot but it’s clearer to declare a list of functions and assign to $scope.

//lazy way to declare $scope functions:
$scope.func1 = function() {
  ...
};

$scope.func2 = function() {
  ...
};

//neat way to declare $scope functions with overview 
//over all of them:
function func1() {
  ...
}

function func2() {
  ...
}

//assignments near the end of file for overview
$scope.func1 = func1;
$scope.func2 = func2;

Template for a neat AngularJS controller:

angular.module("My_Module").controller("my_controller",[
"$rootScope","$scope","$http","$location","$cookies",...,
function($rootScope,$scope,$http,$location,$cookies,...){
 
  //non-scope variables
  var My_Var1;
  var My_Var2;
  ...

  //scope variables
  $scope.My_Var1;
  $scope.My_Var2;
  ...

  //non-scope functions 
  //(can be called or assigned as scope functions)
  function my_func1() {
    ...
  }

  function my_func2() {
    ...
  }

  //scope functions (assignments from non-scope functions only)
  //this is is for overview of all functions available
  $scope.my_func1 = my_func1;
  $scope.my_func2 = my_func2;
  ...
}]).
directive("myDirective",function(){ //in html: my-directive
  return function(Scope,Element,Attrs){
    ...
  };
});
Advertisements