Skip to content

Instantly share code, notes, and snippets.

@ry8806
Last active September 13, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry8806/a0e2662d67cc2614b9c5e5f80d78fb4e to your computer and use it in GitHub Desktop.
Save ry8806/a0e2662d67cc2614b9c5e5f80d78fb4e to your computer and use it in GitHub Desktop.
app.filter('textfilter', [function() {
return function (input) {
if (arguments.length > 1) {
// If we have more than one argument (insertion values have been given)
var str = input;
// Loop through the values we have been given to insert
for (var i = 1; i < arguments.length; i++) {
// Compile a new Regular expression looking for {0}, {1} etc in the input string
var reg = new RegExp("\\{" + (i-1) + "\\}");
// Perform the replace with the compiled RegEx and the value
str = str.replace(reg, arguments[i]);
}
return str;
}
return input;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment