Promises are asynchronous. The problem is that when you get to console.log , the $promise.then code is not already running . You must wait for the promise to be fulfilled before you can access this data.
Any operation you want to apply to a value must be performed internally , this callback function that you pass is then :
resp1.$promise.then(function (data) { var data1 = data.resource.resource;
AngularJS can update your HTML when it receives data, because $promise is Angular -aware - it knows that after your callback starts, it should tell AngularJS to refresh / redraw your page (and thus refreshing the data) .
source share