qwertyking qwertyking - 4 months ago 4
AngularJS Question

Angular lowercase and replace spaces with dashes in json data

Here is my data:

{
"statusCode": 200,
"result": {
"items": [
{
"Name": "date",
"Fields": {
"{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
"Name": "Promo Content",
"Value": "September 22, 2015"
}
}
},
{
"Name": "rate",
"Fields": {
"{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
"Name": "Promo Content",
"Value": "10%"
}
}
},
{
"Name": "description",
"Fields": {
"{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
"Name": "Promo Content",
"Value": "This rate is good as of the date listed above."
}
}
}
]
}
}


And here is my HTML and JS:

<body ng-app="myApp">

<div ng-controller="CallWebApi">
<ul>
<li ng-repeat="item in data">
{{ item.Name }}: {{ item.Fields["{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}"].Value }}
</li>
</ul>
</div>
<script>
angular.module('myApp',[]).controller('CallWebApi', function($scope, $http) {
// Local version of the data
$http.get('./test.js').

success(function (data) {
$scope.data = data.result.items;
console.log('success ' + data)
})
.error(function(data) {
console.log('failure ' + data)
});
});
</script>
</body>


How would I write out the description with letters lower cased, and spaces replaced with dashes?

I'm expecting:


  • date: September 22, 2015

  • rate: 10%

  • description: this-rate-is-good-as-of-the-date-listed-above.


Answer

quertyking,

create a custom filter with

var str = text.replace(/\s+/g, '-');
return str.toLowerCase();

this jsfiddle does it