Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular TypeError: text.replace is not a function. ng-repeat

I am trying to mask all the chars except the last four using a filter in angularjs. I am getting the following error.

Error

HTML :

<table>
...
 <tr ng-repeat="emp in FiltredCorpEmployees  | orderBy:propertyName:reverse" ng-model="emp.evaluationStatusId">
    <td class="col-md-2 text-center">{{emp.hashSSN | MaskText}}</td>
</tr>

..
</table>

JS :

DashBoardModule.filter('MaskText', function () {
    //debugger;
    return function (text) {
        if (!text) {
            return text;
        }
        return text.replace(/.(?=.{4})/g, 'X');
    };
})
like image 477
r mk r Avatar asked Aug 10 '16 23:08

r mk r


1 Answers

Give this a try see what comes up :

 text.toString().replace(/.(?=.{4})/g, 'X')
like image 120
akardon Avatar answered Nov 20 '22 23:11

akardon