I am trying to compare the users choice (gender and country) to that of a json object(gender and country). If the comparison is true, then console.log the json's gender and country's "Value".
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;
//OBTAIN THEIR DEATH AGE
//save their gender and country
var gender = $('select[name=gender]').val();
var country = $('select[name=country]').val();
console.log("GENDER:" + gender + "." + "COUNTRY:" + country);
//get their death age
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"
}
]
}
Don't worry too much on the wiring of the json data, it is working fine. I can obtain the $scope.ages data fine.
genderandcountryvalues? If not, I think you should know that it's a bit peculiar to get them using jQuery when Angular has easier ways of tracking them. Is there a reason you're not using ngModel for them?