Reputation: 11
I have a factory in my app which takes environment uri data as input parameter and returns a $resource object as below. The coreService is a singleton object used in many other controllers of UI. Initially, the app gets registered with default config environment values.Once the user logs in, an event is triggered which changes the environmentData object. Problem here is the coreService still holds the default environmentData values and doesn't take the updated environment data.
angular.module('mbapp.sm')
.factory('coreService', coreService);
coreService.$inject = ['$resource','environmentData'];
function coreService($resource,environmentData) {
return $resource(environmentData.getAppInfoURI(), null,
{
getAppInfo: {
method: 'GET',
headers: {
'Accept': 'application/json'
},
url: environmentData.getAppInfoURI() + "appInfo?appId=:appId"
},
getAllAppHistory: {
method: 'GET',
headers: {
'Accept': 'application/json'
},
url: environmentData.getHistoryURI() + "apps?history=Y&version=1"
},
});
The controller class calls the service as below -
coreService.getAppInfo({
appId: var }).$promise.then(appInfoSuccess, appInfoFailure);
Need help is figuring out a way to update the environmentData as the base uris change. If environmentData.getAppInfoURI() returned "aaa" and later changes to "bbb", the coreService still holds "aaa" value of getAppInfoURI()
Upvotes: 1
Views: 31