Skip to content

Instantly share code, notes, and snippets.

@wodka
Created February 5, 2016 14:14
Show Gist options
  • Save wodka/f2c97d32a4083fd8a559 to your computer and use it in GitHub Desktop.
Save wodka/f2c97d32a4083fd8a559 to your computer and use it in GitHub Desktop.
angular style MS
(function (angular) {
'use strict'; // inside of function -> might break stuff in global context
angular.module('com.acme.module', ['log.ex.uo'])
.factory('AcmeService', AcmeService)
.provider('AcmeConfig', AcmeConfig)
;
AcmeService.$inject = ['$log', '$q', '$http', 'AcmeConfig'];
function AcmeService ($log, $q, $http, AcmeConfig) {
$log = $log.getInstance('AcmeService');
$log.info('Service loaded');
return {
login: function (user, password) {
var deferred = $q.defer();
$http({
method: 'POST',
url: AcmeConfig.getPath('login')
}).then(
function(response) {
deferred.resolve({
status: 'success',
raw: response
});
},
function(error) {
deferred.reject({
status: 'error',
raw: error
});
}
);
}
};
}
function AcmeConfig () {
var config = {};
return {
setPath: function (path, url) {
config[path] = url;
},
$get: function () {
return {
path: function (path) {
return config[path];
}
};
}
};
}
}(angular));
(function (angular) {
angular.module('app', ['com.acme.module', 'log.ex.ui'])
.config(Configuration)
;
Configuration.$inject = ['AcmeConfigProvider'];
function Configuration (AcmeConfigProvider) {
AcmeConfig.setPath('login', 'https://auth.acme.com/login');
}
// and so on :D
}(angular));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment