Reputation: 3779
Update: 02/12/2015
As mentioned in the comments this was an issue with the object being modified by an Angular module. I was able to track this down using toJSON
as mentioned below.
I have recently ran into an issue that has be quite boggled. I have a service that is request data from an api via get
request. When looking on the network panel in Chrome developer tools the api returns the proper results but they are not show in the response from the angular request.
You can note the content section is missing items. And Angular code:
Angular Code
function getPhotos(){
return $http.get('/photo')
.then(getPhotosComplete)
.catch(function(err){
//handle errors
});
function getPhotosComplete(res){
//Showing incorrect response here
console.log("getPhotosComplete", res);
return res.data;
}
}
From API
{
url: "https://dev.amazonaws.com/060a2a5f-8bb7-4ffa-aa7d-e715439271a3.jpg",
archive_name: "140809",
seedcount: 0,
viewcount: 0,
live: true,
current: false,
next: false,
createdAt: "2015-02-10T17:48:41.505Z",
updatedAt: "2015-02-12T04:11:02.239Z",
content: [
"Balloon",
"Apartment",
"Testing",
"Testing 2",
"Party",
"Inez"
],
id: "54da44790eb10b0f00b453a1"
}
Angular Scope / res.data in service
{
url: "https://dev.amazonaws.com/060a2a5f-8bb7-4ffa-aa7d-e715439271a3.jpg", seedcount: 0,
viewcount: 0,
live: true,
current: false,
next: false,
createdAt: "2015-02-10T17:48:41.505Z",
updatedAt: "2015-02-12T04:11:02.239Z",
content: Array[3]
0: "Balloon",
1: "Apartment",
2: "Party"
]
Upvotes: 1
Views: 420
Reputation: 27062
If the output from angular.toJson()
is correct, but the console.log
of the object is wrong, then it strongly suggests the object is being modified in the code somewhere after the call to console.log
.
This is because console.log
takes a reference to an object, and some time later it turns it into a string for output. I would class it as slightly evil behaviour, as it suggests the bug is before the call to console.log
, while actually the issue after it. Hours can be wasted looking through the wrong code...
Upvotes: 3