I want to know if there really is how to make synchronous calls with angularjs.
The problem I have is the following:
I have two URL1 and URL2. URL1._ in this first url what I do is get some values of asignaturas
and c/u
of them has a code. This code will then be used in my URL2 which will return the parallel of the subject depending on the code.
Currently what I have done is use promises in angularjs.
First, I go through URL1 and get its data[i].codigo
and in turn I send it to URL2 so that I can return its corresponding parallel .... But it only returns the first posicion[i]
and the rest does not .
I would like you to guide me with this please. Thank you.
Code:
.service('ServParalelos',function($http, $q){
return {
getAll: getAll
}
function getAll (guid_coe) {
var defered = $q.defer();
var promise = defered.promise;
$http.get('http://carbono.utpl.edu.ec:8080/wscodigosqr/webresources/entidades.qrhorario/horarios_componente?guid_coe='+guid_coe)
.success(function(data) {
defered.resolve(data);
})
.error(function(err) {
defered.reject(err)
});
return promise;
}
})
My controller
$scope.datosComp=data; //esta variable es el data q obtengo de la URL1
var Tamanio = $scope.datosComp.length;
for ( i=0; i < Tamanio; i++) { //Tamanio es del primer url o servicio
**$scope.guid_coe** =$scope.datosComp[i].guid_coe;
ServParalelos.getAll($scope.guid_coe).then(function(data) {
$scope.datosA = data; //en mi sengundo servicio le paso como parametro guid_coe
})
}
My HTML
<ion-view view-title="Subjects">
<ion-content class="fondo">
<div class="list card">
<div class="item item-input-inset">
<label class="item-input-wrapper">
<h4>
Welcome
</h4>
</label>
</div>
</div>
<div class="list card">
<ion-list>
<ion-item type="item-text-wrap" ng-repeat="i in datosComp" href="#/Gtuto/componentes/{{i.nom_coe}}">
<h3>{{i.nom_coe}}</h3>
<h3 ng-repeat="i in InfoComp">{{i.paralelo}}</h3>
</ion-item>
</ion-list>
</div>
</ion-content>
</ion-view>