Problem
I have an AngularJS application, and for some reason, one of my loops is forEachnot working. The loop seems to work when a function is pressed on a button, but it does not work on boot.
the code
So, I have my controller configured correctly for the page. I call a function in my service that runs in my API and returns an array to me:
controller
var holidaysnew = getUserEventsById.getUserEventsById();
Service
app.service('getUserEventsById', function ($http) {
this.getUserEventsById = function () {
var holidays = [];
$http.get("http://localhost:9847/AceTracker.svc/GetAllEventsByUser?user_id=1").success(function (data) {
for (var key in data.GetAllEventsByUserResult) {
if (data.GetAllEventsByUserResult.hasOwnProperty(key)) {
holidays.push(data.GetAllEventsByUserResult[key])
}
}
});
return holidays;
};
});
Thus, at the initial loading of the page, it is holidaysnewsuccessfully deleted and represents an array of holidays. Below the line where my loop is forEach, I want to go through holidaysnew, but it doesn't seem to be in the loop.
The loop is encoded as follows:
holidaysnew.forEach(function (hol) {
$scope.eventSources[0].events.push({
end: $filter('dateFilter')(hol.HOLIDAY_END),
start: $filter('dateFilter')(hol.HOLIDAY_START),
title: hol.HOLIDAY_TITLE,
color: $filter('colorEventFilter')(hol.HOLIDAY_EVENT_STATE_ID)
});
});
I have an console.logarray holidaysnewand it is definitely populating. Can anyone see the problem?
:
, (. )

$scope.eventSources[0].events = holidayEvents; , .
holidayEvents ?
EDIT2:
JSON, :
{"GetAllEventsByUserResult":[{"HOLIDAY_END":"\/Date(1456358400000+0000)\/","HOLIDAY_EVENT_ID":1,"HOLIDAY_EVENT_STATE_ID":1,"HOLIDAY_START":"\/Date(1455926400000+0000)\/","HOLIDAY_TITLE":"Spain ","USER_ID":1},{"HOLIDAY_END":"\/Date(1454371200000+0000)\/","HOLIDAY_EVENT_ID":2,"HOLIDAY_EVENT_STATE_ID":2,"HOLIDAY_START":"\/Date(1454284800000+0000)\/","HOLIDAY_TITLE":"Italy ","USER_ID":1},{"HOLIDAY_END":"\/Date(1458000000000+0000)\/","HOLIDAY_EVENT_ID":3,"HOLIDAY_EVENT_STATE_ID":1,"HOLIDAY_START":"\/Date(1457568000000+0000)\/","HOLIDAY_TITLE":"Germany ","USER_ID":1},{"HOLIDAY_END":"\/Date(1481068800000+0000)\/","HOLIDAY_EVENT_ID":4,"HOLIDAY_EVENT_STATE_ID":3,"HOLIDAY_START":"\/Date(1480896000000+0000)\/","HOLIDAY_TITLE":"England ","USER_ID":1}]}