I am trying to get the provCode
or ID
from the provinceData
from getFunction()
. I did that by using angular.forEach()
, but I didn't expected to get the following error.
Notice: Undefined property: stdClass::$provCode in C:\xampp\htdocs\student-violation-system\php\address\cities.php on line 5
[]
I tried to change the {provCode: provCode}
to just provCode
also not working.
So, I tried to change the {provCode: provCode}
to {provCode: '0456'}
and it works.
But ofcourse it is not what I want, I want it to be dynamic. I wonder why it is saying the Undefined property
because I tried to console.log
the provCode
inside the getCity()
and it has a expected value of 0456
. So, I wonder why it is saying Undefined property
.
app.factory
factory.getProvince = function(){
return $http.get('php/address/province.php').then(function(response){
provinceData = response.data;
console.log(provinceData);
angular.forEach(provinceData, function(value, key) {
if(value.provDesc == province){
provCode = provinceData[key].provCode;
}
}); // angular.forEach
return provinceData;
})
}
factory.getCity = function(){
return $http.post('php/address/cities.php', {provCode: provCode}).then(function(response){
console.log(provCode);
municipalityData = response.data;
console.log(municipalityData);
return municipalityData;
})
}
return factory;
cities.php
<?php
include("../../connection.php");
$data = json_decode(file_get_contents("php://input"));
$provCode = $data->provCode;
$db->query('SET CHARACTER SET utf8');
$cities = $db->query(" SELECT * FROM refcitymun WHERE provCode='$provCode' ");
$cities = $cities->fetchAll();
echo json_encode($cities);
?>
UPDATE
I log the $data
in cities.php and it was returning null
value. I don't know why because I console.log
the provCode
inside the getCity
function and it is returning the right value/data I was expecting. Can someone explain it to me what is happening? My mind is going crazy on this one.
By the way it is one of my ongoing approach on how to solve my issue on this: Anglularjs passing value from Controller, State Resolve and Factory Service