When do we need to bind an method to $scope in controller,i am dealing with methods which is just mapping operation on object.
Example :
$scope.myVar = {};
function myMyObject(x) {
$scope.myVar = {
"xKey":x
}
}
to
$scope.myMyObject = function(x) {
$scope.myVar = {
"xKey":x
}
}
myMyObject(10);
$scope.myMyObject(10);
Is it necessary to bind $scope to myMyObject method here ?
Bind methods to $scope
only when they will need to be called from the View. If they are just private methods that you only call from the controller itself, there's no need to pollute the scope.
In your specific scenario, there is no need to bind myMyoObject()
to the scope.
Edit: You can avoid using $scope altogether and use controllerAs syntax, in which case instead of binding to $scope, you bind to this. The non-public functions still will be kept unbound to anything.