Here is a simple, compact and straightforward method that I use. First add the service in js.
app.factory('Helpers', [ function() { // Helper service body var o = { Helpers: [] }; // Dummy function with parameter being passed o.getFooBar = function(para) { var valueIneed = para + " " + "World!"; return valueIneed; }; // Other helper functions can be added here ... // And we return the helper object ... return o; }]);
Then in the controller, enter your helper object and use any available function using the following:
app.controller('MainCtrl', [ '$scope', 'Helpers', function($scope, Helpers){ $scope.sayIt = Helpers.getFooBar("Hello"); console.log($scope.sayIt); }]);
source share