Phạm Quốc Bảo Phạm Quốc Bảo - 16 days ago 5
AngularJS Question

AngularJS: JSON.parse(data).success is not defined

I'm trying to use JSON.parse the data:[{"id":"ABC123","provider_type":"Center","name":"Test1","phone":"03 2222 9999","mobile":"1111 123 123","email":"abc@gmail.com","address":["3999, Victoria","Est Danvale","113 HD streed","Block D, K House."]}]

and code:

var callBackProviderSuccess = function(data){
var providerObj = JSON.parse(data);
if(providerObj.success) {
$scope.providerInfo = providerObj.provider;
$localStorage.providerJPayInfos = $scope.providerInfo; IBMService.getStaffsOfProvider(providerID).then(callBackStaffsSuccess,callBackStaffsError);

} else {
$scope.infoLoadingText = "Provider not found on our database";
//try again
IBMService.getProviderById(providerID).then(callBackProviderSuccess,callBackProviderError);
}
};


when debugging at if(providerObj.success), i have a message: providerObj.success undefined. Please help me give your thoughts.
Thanks

Answer

Yes there is no success property inside the JSON .

Change it as,

if(providerObj) {