jecorrales jecorrales - 22 days ago 9
AngularJS Question

How can i manipulate an object

This is on my PHP:

if(whatever)
{
echo("GOOD"
}
else
{
$result['msg'] = "Mesagge for AngularJS";
}
echo json_encode($result);


And this is what I getting for angular:

.service('upload', ["$http", "$q", "$location", function ($http, $q, $location, $scope)
{
this.uploadFile = function(file, idPunto)
{
var deferred = $q.defer();
var formData = new FormData();
formData.append("name", idPunto);
formData.append("file", file);
return $http.post("Uploads/server.php", formData, {
headers: {
"Content-type": undefined
},
params: {id: idPunto},
transformRequest: angular.identity
})
.then(function successCallback(res)
{
//Here I need to comparate the object result from PHP
if(res.data == 'message from PHP')
{
$location.url("/controlPanel");
}
else
{
console.log("not is equal");
}
deferred.resolve(res);
}
,function errorCallback(msg, code)
{
deferred.reject(msg);
})
return deferred.promise;
}
}])


Result: Object { msg: "Mesagge for AngularJS" }
on the function (res)

So, I need to comparate the object result

I can't use $scope, because at service from angular can't used whit it.

//Example of that.
$scope.tableRepeat= dataImages.data;

Answer Source

You were really close, just had to unpack the response object a bit more.

In your successCallback, use res.data.msg for your evaluation, rather than just res.data.