I am getting the following JSON response:
{
"systemDefence": 0,
"sensorsDefence": [{
"index": 1,
"defence": 0
}, {
"index": 2,
"defence": 3
}, {
"index": 3,
"defence": 3
}, {
"index": 4,
"defence": 3
}, {
"index": 5,
"defence": 0
}]
}
With the simplified code i was able to receive and return a response to a web page field. But what i am trying to achieve now is to rename the value for "index" and "defence" with the following formula:
- 1 - Name1, 2 - Name2, 3 - Name3, etc.
- 1 - activated, 2 - not activated, 3 - something...., etc
Planned output should look like:
index : Name1
defence : activated
index : Name2
defence : something
I have used the following script to rename the values but in this case doesn't work anymore:
JSON response:
{
"temperature": 23,
"light": 0,
"noisy": 0,
"air": 0,
"humidity": 43.300000
}
<div ng-app="myApp" ng-controller="myCtrl">
Temperature : {{content.temperature}}
Humidity : {{content.humidity}}
Air : {{output_air}}
</div>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("URL")
.then(function(response) {
$scope.content = response.data;
if($scope.content.air == "0"){
$scope.output_air = "excellent";
}
else if($scope.content.air == "1"){
$scope.output_air = "good";
}
else{
$scope.output_air = "bad";
}
});
});
Any suggestion/solution is welcome. Thanks in advance!