I have some data being pulled in from an API in my controller with $http.get I then want to apply a text formatting filter to that text to make it all pretty.
However I am getting
TypeError: Cannot read property 'split' of undefined
all over my console.
Here's the code:
Controller $http get:
$http.get("url to my api data")
.success(function (data, status, headers, config) {
$scope.serviceStatus = data;
})
.error(function () {
});
Filter within module:
app.filter('textFormat', function() {
function format(input) {
// Call the passed in endpoint and at any capitalised letters, split it to have a space between words
input = input.split(/(?=[A-Z])/).join(" ");
// Get the character at index 0 and modify it to be uppercase. Then append the rest of the split string to the end
input = input.charAt(0).toUpperCase() + input.slice(1);
return input;
};
format.$stateful = true;
return format;
});
HTML:
<div ng-repeat="services in serviceStatus">
<p>The {{ services.service | textFormat }} is {{ services.status | textFormat }}</p>
</div>