Luiggi Luiggi - 1 year ago 60
JSON Question

Receive data from JSON AngularJS with 2 keys

I can't read data from my JSON that I receive from a called php and my Controller it's like this:

app.controller('equipoCtrl', ['$scope', '$routeParams', '$http', function($scope,$routeParams,$http){

var idEquipo = $routeParams.idEquipo;
$scope.actualizado = false;
$scope.alumno = {};

$http.get('php/servicios/equipos.getEquipo.php?c='+ idEquipo)

if (data.err !== undefined) {
window.location = "#/equipos";
$scope.alumno = data;





The result of my array called
looks like:

[ { "idPosicion": "2", "posicion": "Delantero" }, { "idPosicion": "1", "posicion": "Portero" } ]

Finally my HTML code:

<div class="col-md-6">
Posicion Jugador 1:{{posicionSeleccionada}}
<select ng-model="posicionSeleccionada" class="form-control" >
<option ng-repeat="(key,value) in myposition" value=""></option>

Somebody can help me, how can retrieve the values?

Thanks, Luiggi

Answer Source

You are using object syntax when you need to use array syntax

<option ng-repeat="pos in myposition" value="{{pos.idPosicion}}">{{pos.posicion}}</option>

Also suggest looking into using ng-options

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download