After spending several hours researching Kris Kowal's Q library and the angularjs $q variable, I am still struggling to comprehend how it all works.
Currently, my service contains the following code:
resetpassword: function (email, oldPassword, newPassword) {
var deferred = $q.defer(); //I find myself questioning why I need this
var promise = auth.$changePassword(email, oldPassword, newPassword); //$changepassword in angularfire returns a promise
console.log(deferred); //An object with resolve, reject, notify, and promise attributes is displayed
var rValue = promise.then(function(){
//success callback
return 1; //this is expected behavior if changepassword succeeds
}, function(error){
//error callback
return error.code; //handles scenarios like wrong password input
}
);
deferred.resolve(promise); //Is this necessary? I assumed my promise was resolved in the callbacks
console.log(rValue); //The output is another promise. How can I access 1 or error.code values?
return rValue; //My intention is to return 1 or error.code back to the controller
},