Skip to content

Instantly share code, notes, and snippets.

@tonyjoanes
Created October 21, 2019 11:23
Show Gist options
  • Save tonyjoanes/924ec81d04303921fa0afe83d29d0181 to your computer and use it in GitHub Desktop.
Save tonyjoanes/924ec81d04303921fa0afe83d29d0181 to your computer and use it in GitHub Desktop.
AngularJS Services
(function () {
'use strict';
var serviceId = 'myService';
angular.module('app', serviceId);
myService.$inject = ['dependencyOne', 'dependencyTwo'];
function myService(
dependencyOne,
dependencyTwo
) {
var privateVariable = 15156;
var api = {
myFunction: myFunction
}
return api;
function myFunction() {
// do some cool stuff in here
}
/////////////////////////////////////////
// private functions can go below here //
/////////////////////////////////////////
function privateFunction(val1, val2) {
return privateVariable * (val1 + val2);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment