Created
February 5, 2016 14:14
-
-
Save wodka/f2c97d32a4083fd8a559 to your computer and use it in GitHub Desktop.
angular style MS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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