javascript - How can I use callbacks between two AngularJS factories? -
in angularjs app got 2 factories called "editinfo" , "pinverify". i'm trying have editinfo factory call pinverify service callback function pinverify.sendpin(this.saveinfo)
, save method inside pinverify factory when user has inputted pin , presses button calling pinverify.pinentered()
the problem callback-method copied pinverify object , unable reference properties in editinfo factory.
so... naturally tried using $q.defer()
inside pinverify factory instead, , resolve in pinverify.pinentered()
when user enters pin sent out sms.
this works fine, , can inside editinfo factory instead of using callbacks:
pinverify.sendpin().then(function() { this.saveinfo(); }
and saveinfo method detect if pin correct , hide modal enter it. problem arises when pin is not correct.
the promise has been resolved, click on button calling pinverify.pinentered
nothing basically. can not resolve twice.
so i'm kind of started, , considering heavy drinking while on job...
any suggestions how can accomplish kind of relationship between 2 factories? suggestions on beers/vodkas works guess.
while first try before going $q promise looked , didn't work - pinverify.sendpin(self.saveaddress);
i solved myself using closure-method callback , inside calling actual method using declared var self = this;
this
pinverify.sendpin(function() { self.saveaddress(); });
Comments
Post a Comment