Skip to content

Instantly share code, notes, and snippets.

@klaascuvelier
Last active December 19, 2015 21:09
Show Gist options
  • Save klaascuvelier/6018363 to your computer and use it in GitHub Desktop.
Save klaascuvelier/6018363 to your computer and use it in GitHub Desktop.
/**
* URL service, holding urls for JS
*/
Module.factory('$url', function Url() {
var $url = {
_urls: {},
/**
* Store a specific route
* @param {string} key
* @param {string} url
*/
set: function (key, url) {
this._urls[key] = url;
return this;
},
/**
* Get a specific rout
* @param {string} key
* @param {array} params
* @return {string}
*/
get: function (key, params) {
var url = this._urls[key] || '';
if (typeof params === 'object') {
angular.forEach(params, function (value, index) {
var parameter = new RegExp(':' + index, 'g');
url = url.replace(parameter, value);
});
}
return url;
}
};
return $url;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment