I came across a situation where I need to filter elements created with the 'ng-repeat' directive, but I applied a custom filter that changes one character to another and vice versa for each element created.
Then, if I look for a new character that has been replaced, the filter will not find it - unless I look for the old one.
How to apply this input filter after using my custom filter that changes characters?
In my custom brNumber filter, the points are swapped with commas and vice versa, so if I search for a point, the filter will only find those that have a comma.
Fiddle
<HTML>
<div ng-app="myApp" ng-init=" person= [ {firstName:'Johnny',lastName:'Dowy'}, {firstName:'Homem,25',lastName:'Cueca,Suja'}, {firstName:'Alleria.Donna',lastName:'Windrunner'} ];" > First Name: <input type="text" ng-model="firstName"> <br /> The persons objects have: | <span ng-repeat="i in person | orderBy: 'firstName' | filter:firstName">{{ ( i.firstName + ' ' + i.lastName ) | brNumber }} | </span>
{Javascript.js}
app.filter( 'brNumber', function() { return function( text ) { string = text.toString(); returnString = ''; for ( i = 0; i < string.length; i++ ) { returnString += string[i] === ',' ? '.' : ( string[i] === '.' ? ',' : string[i] ); } return returnString; } });
javascript html angularjs
Kind jason
source share