In my project, I am attempting to match the selected user's gender and country with those stored in a JSON object. If the comparison yields a positive result, I want to display the corresponding "Value" for that gender and country from the JSON data.
JS:
var app = angular.module('deathApp', []);
app.controller('data', function ($scope, $http) {
$http.get("angular/death/data.json")
.success(function (response) {
$scope.ages = response.fact;
//Extract their age at death
//Retain their gender and country information
var gender = $('select[name=gender]').val();
var country = $('select[name=country]').val();
console.log("GENDER:" + gender + "." + "COUNTRY:" + country);
//Retrieve their age at death
if (gender && country === gender and country from $scope.ages) {
console.log(this.$scope.ages['Value'])
}
json:
{
"fact": [
{
"COUNTRY": "Afghanistan",
"SEX": "Female",
"Value": "62"
},
{
"COUNTRY": "Afghanistan",
"SEX": "Male",
"Value": "61"
},
{
"COUNTRY": "Albania",
"SEX": "Female",
"Value": "76"
},
{
"COUNTRY": "Albania",
"SEX": "Male",
"Value": "73"
},
{
"COUNTRY": "Algeria",
"SEX": "Female",
"Value": "74"
},
{
"COUNTRY": "Algeria",
"SEX": "Male",
"Value": "70"
}
]
}
I am not concerned about how the JSON data is structured, as it is functioning correctly. I can successfully access the $scope.ages data.