Alex Man Alex Man - 7 months ago 6
Javascript Question

Removing all spaces from angular js ng-repeat variable

In one of my angular application I will get the values when I pass the key in ng-repeat.

Here each rows in rowsdata has values like

'my file1 data', 'my file2 data', 'my file3 data'

But I need to pass it as
'myfile1data', 'myfile2data', 'myfile3data'

When I used rows.replace(' ','') it is removing only the first space like
'myfile1 data', 'myfile2 data', 'myfile3 data'

<tr ng-repeat="data in datas">
<td ng-repeat="rows in rowdatas">{{data[rows.replace(' ','')]}}</td>


But when I use

<td ng-repeat="rows in rowdatas">{{data[rows.replace(/ /g,'')]}}</td>

I got

Error: a is not a function OPERATORS["/"]@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/a‌​ngular.js:5959 OPERATORS["/"]@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/a‌​ngular.js:5959 binaryFn/<@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/angul‌​ar.js:6292

Can anyone show me some solution for this?


Try this:

rows.replace(/ /g,'')
<tr ng-repeat="data in datas"> 
    <td ng-repeat="rows in rowdatas">{{rows.replace(/ /g,'')}}</td>

Rows should already be the list item. For details of replace check here; it has actually nothing to do with angular.