What you are looking for in AngularJS is called filter
.
A filter
takes an input value and optional configuration parameters, and returns a value that will actually be displayed in the interface.
A filter
is created as follows:
angular.module('MeuModulo', []).filter('nomeDoFiltro', function() {
return function(input, arg1, arg2) {
var out;
// manipula input e seus argumentos...
return out;
};
});
For example, a filter that transforms a string into uppercase
when parameter is true
, and in lowercase
when the parameter is false
:
angular.module('MeuModulo', []).filter('case', function() {
return function(input, uppercase) {
var out = "";
if ( uppercase ) {
out = input.toUpperCase();
} else {
out = input.toLowerCase();
}
return out;
};
});
This filter can then be used in your HTML:
<p>{{ 'minha string' | case:true }}</p>
Echoing after rendered by AngularJS:
<p>MINHA STRING</p>
See more about creating filters in the AngularJS documentation:
Developer Guide: Filters
Creating the filter for the CNPJ stays as an exercise!