When working with Angular, it is common practice to define methods in your controller by attaching them to either $scope
or this
:
$scope.myFunction = function () { ... }
Alternatively, you can attach methods to this
, which is often used for communication between directives and a parent controller:
/* within the controller */
this.myFunction = function () { ... }
Is there a difference in performance between these two approaches since Angular watches the values?
Regardless of performance considerations, using this method can help keep certain functions private and prevent accidental access from the View.