0
I have a Factory that must access two other services. Being the following structure:
angular.module('my.module')
.factory('ServiceMain', ServiceMain);
ServiceMain.$inject = ['ServicePrimary', 'ServiceSecondary'];
function ServiceMain(ServicePrimary, ServiceSecondary){
var service = {
execute: execute
}
return service;
function execute(){
ServicePrimary.getData().then(function(result){
var arrayData = [];
var indiceForSync = 0;
for(var indice = 0; indice < result.length; indice++ ){
if(result[indice].valor <= 0){
continue;
}
arrayData[indiceForSync] = {
clientes: result[indice],
pacotes: []
}
indiceForSync++;
}
if(arrayData.length) {
for (var indiceData = 0; indiceData < arrayData.length; indiceData++) {
ServiceSecondary.getPackages(arrayData[indiceData].valor).then(function(packs){
//Aqui nao eh possivel enxergar o arrayData...
for(var indicePacks = 0; indicePacks < packs.length; indicePacks++ ){
//a ideia era chamar o array data para preencher o array pacotes
arrayData[indiceData].pacotes[indicePacks] = packs[indicePacks];
}
});
}//end for
}
});
}
}
Within the call of the second service (Servicesecondary), within the Omise I do not have access to the variable arrayData. I’ve tried calling this (something like: var vm = this;
) and then declare it with vm.arrayData
, and last act, I tried to use $rootScope, but nothing works.
Is there a way to access this variable within the scope of Promise? or is the implementation having problems?