I have some experience in AngularJS, but the fact that I can't figure out how to handle a regular function inside a AngularJS controller keeps bothering me. For the record I am talking about a function that handles parts of small business logic inside the controller, that doesn't need to be shared across controllers. I have found two ways to handle such regular functions that don't need binding from the view.
The first way I have found is to just use: $scope.myFunction = function(){} but the fact that it can be used directly from the view doesn't seem correct.
The second way I have found is to just use a regular Javascript function: function myFunction(){} but I don't know how the visibility of such functions is in AngularJS.
Is there a "correct" way of ensuring a limited visibility inside a controller? Or should I keep using the regular Javascript function?
Just the same way as you would define a "local" function within a standard closure:
localFuncandlocalFuncHoistedare identical in most cases, however each has its own benefits. The hosted function is visible to all code, before and after declaration.localFunccan be set only when needed and removed when not.