I have the following array:
$scope.arreglo = [
{"clave_acceso":"122"},
{"clave_acceso":"222"},
{"clave_acceso":"333"}
];
and from the desire to create a url which should be like the following: If the array has a data: http:services/autorizaciones?ca=122 If the array has more than one data: http:services/autorizaciones?ca=122&ca =222&ca=33.......etc
In my controller I have the following:
$scope.url ="";
$scope.arreglo = [
{"clave_acceso":"122"},
{"clave_acceso":"222"},
{"clave_acceso":"333"}
];
for(var i =0; i < $scope.arreglo.length;i++){
if($scope.arreglo.length >= 2){
$scope.url="http:services/autorizaciones?ca="+$scope.arreglo[i].clave_acceso+"&ca="+$scope.arreglo[i].clave_acceso;
}else{
$scope.url="http:services/autorizaciones?ca="+$scope.arreglo[i].clave_acceso;
}
}
and at the end of everything I print in my html view the url
<h5>{{url}}</h5>
But I'm doing something wrong that doesn't show up as I expect.
How can I solve that? I thank you in advance
We will simply concatenate them
clave_acceso
to a stringurl = "http:services/autorizaciones";
When the for ends, the result is :
http:services/autorizaciones&ca=122&ca=222&ca=333
and with the replace function we remove the first
&
one and replace it with?
use the variable
url
to display in the view