I want to do some treatment once the function I called, which performs a call to the server, is done.
I tried :
vm.myFunction().$promise.then(function(){
//some treatment done once vm.myFunction() is finished....
})
vm.myFunction = function(){
var deferred = $q.defer();
myResource.get(function(result){
vm.results = result;
for (var i=0; i<vm.results.length;i++){
if (vm.results[i].state == 'open'){
deferred.resolve();
return deferred.promise;
}
}
})
};
But I ma getting a
angular.js:13294 TypeError: Cannot read property '$promise' of undefined
How can I do that?
return myResource.get(), also there is no case where you will reject it - just to make sure you dont end up in infinite wait or add a timeoutmyResource.get(//code)function. And no need to use$promiseas you are already returning the promise.