Skip to content

Instantly share code, notes, and snippets.

@JsAndDotNet
Created January 7, 2015 16:21
Show Gist options
  • Save JsAndDotNet/7711a985a64db64f66ae to your computer and use it in GitHub Desktop.
Save JsAndDotNet/7711a985a64db64f66ae to your computer and use it in GitHub Desktop.
Using AngularJS, this method takes a string bound in the UI and replaces it as required
// Usage
// {{myIntValue | number:0 | replacestringfilter:',':'.'}}
// {{myStringValue | replacestringfilter:'ABC':'DEF'}}
myApp.filter('replacestringfilter', function () {
return function (item, oldstring, newstring) {
if (!item)
return item;
var sItem = item.toString();
var find = oldstring;
var re = new RegExp(find, 'g');
sItem = sItem.replace(re, newstring);
return sItem;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment