Created
January 7, 2015 16:21
-
-
Save ukcoderj/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
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
// 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