Last active
September 13, 2016 12:43
-
-
Save ry8806/a0e2662d67cc2614b9c5e5f80d78fb4e 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
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