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>
</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/angular.js:5959 OPERATORS["/"]@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/angular.js:5959 binaryFn/<@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/angular.js:6292
Can anyone show me some solution for this?
The cleanest way to do so, that I've found, is to create a filter:
angular.module('moduleFilters', []).filter('classy', function() {
return function(text) {
return String(text).replace(/\s*/mg, "-");
};
});
I've called mine classy, as in my use case, it's to make variables valid for classes. Let's call yours compress
as we're compressing out spaces.
Then in your html just call
<tr ng-repeat="data in datas">
<td ng-repeat="rows in rowdatas">{{rows|compress}}</td>
</tr>
Now you can call the compress
filter from anywhere you import that filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With