Greetings! I am currently working on a web application using AngularJS. Within my project, I have a JavaScript file containing two factories that make HTTP calls to a web API. My goal is to utilize the output of one factory within another factory. Below is the code for my initial factory:
myapp.factory('sadadpaymentapi', ['$http', '$cookieStore', 'cfg', 'ScrollFunction', 'leaselisting','$q', function ($http, $cookieStore, cfg, ScrollFunction, leaselisting,$q) {
var sadadpaymentapiobject = {};
var baseurl = cfg.Baseurl;
var LoginID = $cookieStore.get("LoginID");
var cookiePreferredLanguage = $cookieStore.get('PreferredLanguage');
var urlapi = baseurl + "api/ServiceRequest/CreateRSSedad/";
sadadpaymentapiobject.callsadad = function (PaymentType) {
var request = {
url: urlapi,
method: 'POST',
data: {
SRActivityID: LoginID,
PaymentType: PaymentType,
PaymentAmount: "100" //Need to get value from another factory
},
headers: ScrollFunction.getheaders()
};
return $http(request);
}
return sadadpaymentapiobject;
}]);
Next, we have another factory that provides the required value for the PaymentAmount parameter in our previous factory.
myapp.factory('leaselisting', ['$http', '$cookieStore', 'cfg', 'ScrollFunction','$q', function ($http, $cookieStore, cfg, ScrollFunction,$q) {
var leaselistingobject = {};
var baseurl = cfg.Baseurl;
var LoginID = $cookieStore.get("LoginID");
var cookiePreferredLanguage = $cookieStore.get('PreferredLanguage');
leaselistingobject.getValue = function () {
var requestObj = {
url: baseurl + "api/ServiceRequest/GetROLSPSRLeaseList/",
method:'POST',
data: {
LoginID: LoginID,
AccountNumber: $cookieStore.get("AccountNumber")
},
headers: ScrollFunction.getheaders()
};
return $http(requestObj).then(function (response) {
return response.data;
});
}
return leaselistingobject;
}]);
When attempting to inject
PaymentAmount: leaselisting.getValue()
and checking the console log with console.log(leaselisting.getValue());
, a Promise {$$state etc. is returned. Referencing the provided screenshot, what I require from this setup is the variable AccountNumber.
In my first API call, rather than hardcoding PaymentAmount: "100"
, I aim to retrieve it from the other factory. Any guidance on achieving this would be greatly appreciated. Thank you.