angular-phonegap icon indicating copy to clipboard operation
angular-phonegap copied to clipboard

Promises

Open fesor opened this issue 11 years ago • 0 comments

This will be much better to use promises in your library.

And instead of:


function success(fileUrl) {
    console.log('success: %s', fileUrl);
    mySuperCoolService(fileUrl).then(...);
}
function err(reason) {
    console.log('failed: %s', reason);
}

camera.takePicture(success, err);

user may use this:

camera.takePicture()
  .then(function (fileUri) {

     return mySuperCoolService(fileUrl)
  }, function (reason) {

     return $q.reject(reason);
  })
  .then(function (result) {
      return result; // some result processing...
  })
;

This is also solves issue that user should manually call $apply as you should do it from services.

fesor avatar Oct 19 '14 13:10 fesor