I have created angular service where I store my older non-angular javascript functions:
myApp.service('utils', function() {
return {
fun1: function(a, b, c, d) {
var x = a + b + c + d;
return x;
},
fun2: function() {
var x = fun1(1, 1, 1, 1);
return x;
}
};
});
If I call utils.fun2() in controller:
myApp = angular.module('myApp', []);
myApp.controller('myController', ['$scope', 'utils', function($scope, utils) {
$scope.someNumber = utils.fun2();
}]);
I get an error:
Error: fun1 is not defined
My question is, how to rewrite this that it will work (without polluting the global namespace)? What is the best approach for including existing Javascript functions to new angular app?