angular.module('finalApp').controller('WarningsCtrl', function ($scope,HttpService) {
HttpService.get('/warings/snowstrome').error(function(data){
data={
values:[
{
wariningtype:'snowstrome',
warningtitle: 'Severe Snowstrom Warning',
agentid: 100,
name: 'Otaru-Shi',
location:'Hokkaido',
timezone: 'Feb 16,4:35pm Jst',
zip:'0470028, 0470035, 0470154',
weatherstatus:'Snow, Ice and Low Temperature Expected',
weatheralerts:'Automated Alert Sent to 45 Customers',
affectedcustomers:'Affected Customers HR:20, MR:20, LR:20'
}
]
};
$scope.liveCards=data;
});
console.log($scope.liveCards)
});
Asked
Active
Viewed 1,203 times
2

Nikhil Aggarwal
- 28,197
- 4
- 43
- 59

KPR Krishnachaitanya
- 389
- 1
- 3
- 14
-
You can't, the request is asynchronous. You are trying to log the response before it has been returned from server. Read: http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call – charlietfl Jul 17 '15 at 19:30
1 Answers
1
$scope is accessible outside the get call. The console must not be showing updated data due to asynchronous nature of AJAX calls.
You can try updating function like following
angular.module('finalApp').controller('WarningsCtrl', function ($scope,HttpService) {
var getSnowStromeWarning = function(callback) {
HttpService.get('/warings/snowstrome').error(function(data){
data={
...
};
$scope.liveCards=data;
callback();
});
}
getSnowStromeWarning(function(){
console.log($scope.liveCards)
});
});

Nikhil Aggarwal
- 28,197
- 4
- 43
- 59