I have an array with object in $scope in angularjs. I successfully push the object into array. It shows array is form in console but I can't retrieve the last object of array like normal array in javascript. The following is my code.
$scope.messages = [];
$http.get("http://localhost/php/retrieve_message.php").success(function (data)
{
for (i = 0; i < data.length; i++)
{
$scope.messages.push(data[i]);
console.log("success");
}
}).error(function ()
{
console.log("error");
});
console.log([$scope.messages); console.log($scope.messages[$scope.messages.length - 1]);
$httpis an async method. If youconsole.logout of them, it's return empty or undefined.