Removing all spaces from angular js ng-repeat variable

In one of my angular applications, I will get values ​​when I pass the key to ng-repeat.

Here, each row in rowsdata strong> has values ​​such as'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 only removes 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>
</tr>

EDIT

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 someone show me some solution for this?

+4
source share
3 answers

Try the following:

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

Lines should already be an element of the list. Check replacement details here ; it actually has nothing to do with angular.

+3

, , - :

angular.module('moduleFilters', []).filter('classy', function() {
  return function(text) {
    return String(text).replace(/\s*/mg, "-");
  };
});

, , , . compress, .

html

<tr ng-repeat="data in datas"> 
    <td ng-repeat="rows in rowdatas">{{rows|compress}}</td>
</tr>

compress , .

+6
<tr ng-repeat="data in datas"> 
  <td ng-repeat="rows in rowdatas">{{data[rows.split(' ').join('')]}}</td>
</tr>

It works for me!

0
source

Source: https://habr.com/ru/post/1531173/


All Articles