Sample JS code:
$scope.data={"0.19", "C:0.13", "C:0.196|D:0.23"}
.filter('formatData', function () {
return function (input) {
if (input.indexOf(":") != -1) {
var output = input
.split('|')
.map(function (value) {
var splitValues = value.split(':')
return splitValues[0] + ':' + (Number(splitValues[1]) * 100) + "%"
})
.join()
return output;
} else {
return input * 100 + "%";
}
}
})
Example HTML code:
<h1 ng-repeat="item in data|formatData">{{item}}</h1>
Desired output:
"19%"
"C:13%"
"C:19.6%|D:23%"
Error encountered when running the code:
TypeError: input.indexOf is not a function
Looking for solutions to properly handle the data separation within AngularJS.