Hi I have made a controller:
app.controller('CalendarCtrl', ['$scope', 'apiService', function($scope, apiService) {
/* event source that contains custom events on the scope */
$scope.events = [];
apiService.get('events').then(function(results) {
$scope.events = results.data;
console.log(results.data);
});
console.log($scope.events);});
I use two console.log to check the output and the order of calls. And the results.data should return:
[Object]
---> [0]: Object
------> all_day: "1"
------> end: "2016-11-23 10:52:21"
------> id: "1"
------> start: "2016-11-22 10:52:21"
------> title: "Test Event"
------> url: null
---> [1]: Object
...
But in the result, I get my first output as an empty object, which should the output of the second console.log. Which means the controller skip the apiService.get function and run the rest of the code first.
And then I tried
$scope.events = [];
$scope.events = apiService.get('events').then(function(results) {
return $scope.events = results.data;
});
console.log($scope.events);
But this time, I get:
d {$$state: Object}
---> $$state: Object
------> status: 1
------> value: Array[1]
---------> [0]: Object
------------> all_day: "1"
------------> end: "2016-11-23 10:52:21"
------------> id: "1"
------------> start: "2016-11-22 10:52:21"
------------> title: "Test Event"
------------> url: null
Which warp the results I want inside the $$state.
Could anyone tells me why this happen? Thanks.