Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/**
* 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