Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value from resolved defer Angularjs

i am creating android application using ionic and angularjs and using window.requestFileSystem for get image from storage. So for this process i used $q.defer() for asynchronous process and its working fine and showing object in console: console.log(deferred.promise)

enter image description here

but now, when i am trying to get the value from deferred.promise like

var vals = deferred.promise;
console.log(vals.$$state.value);

its showing undefined. Can anyone tell me how i can get that value?

My Code:

var deferred = $q.defer();
    document.addEventListener("deviceready", function() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
            imagePath = fileSystem.root.toURL() + 'SmaartMedia/' + splited[splitedLength-1];
            deferred.resolve(imagePath);
            $rootScope.$apply();
        });
    }, false);
    var vals = deferred.promise;
    console.log(vals.$$state.value);

Thanks

like image 974
Rahul Sharma Avatar asked Jan 23 '26 20:01

Rahul Sharma


1 Answers

function getStuff() {
  var deferred = $q.defer();
  document.addEventListener("deviceready", function () {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
      imagePath = fileSystem.root.toURL() + 'SmaartMedia/' + splited[splitedLength - 1];
      deferred.resolve(imagePath);
      $rootScope.$apply();
    });
  }, false);
  return deferred.promise;
}

//Get value like this
getStuff().then(function(response){
  //Use value here
});
like image 133
Amygdaloideum Avatar answered Jan 25 '26 11:01

Amygdaloideum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!