Last active
December 19, 2015 21:09
-
-
Save klaascuvelier/6018363 to your computer and use it in GitHub Desktop.
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
/** | |
* 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