angular/angular.js — pull request #3877 by jvandemo (2013-09-04 20:16:08+00:00)
Title: Added "replace" filter

This PR adds a "replace" filter to replace substrings inside a string:

{{ 'Hello %name%' | replace:{'%name%': 'AngularJS'} }} // Will display "Hello AngularJS"

The filter accepts a plain JavaScript object as the only parameter with one or more key value pairs and also supports expressions as values like this:

{{ 'Hello %firstName% %lastName%' | replace:{'%firstName%': user.firstName, '%lastName%', user.lastName} }}

This is very handy for websites that need to support different languages and need to replace substrings in translations.

Replacements are also updated on-the-fly when the value expression(s) are changed thanks to the 2-way binding of AngularJS.

This PR also includes the unit tests for the filter.