Error trying to load the options of a select with ng-repat

0

It turns out that I have this object

[{"id":"1","descripcion":"TRIBUNAL ITINERANTE","id_usuario":"1","fecha_de_registro":"2017-04-05 15:57:17"},{"id":"9","descripcion":"TRIBUNAL 2","id_usuario":"0","fecha_de_registro":"2017-04-05 17:14:47"},{"id":"10","descripcion":"TRIBUNAL3","id_usuario":"0","fecha_de_registro":"2017-04-05 17:14:56"}] 

and I need to load these options to a select, I do it in this way but nothing happens: (

<div class="input-field col s12 m12 l6">
          <select>
              <option ng-repeat="x in tipo_de_tribunal" value="{{x.id}}">{{x.descripcion}}</option>
          </select>

          <label>Tribunal</label>
</div>

with this function I charge the data

$scope.openModal = function(div,button) {

        // Asigno el nombre de la accion seleccionada (registrar o modificar)
        $rootScope.button = button;

        // CargarForeignKey

        $rootScope.get('api/tipo_de_tribunal').then(function(response) {
            $scope.tipo_de_tribunal = response;
        });

        // Hacer esto si la accion seleccionada es registrar
        if(button == "registrar") {
            // Desmarca cualquier elemento en la datatable
            $scope.table.rows().deselect();
            // Abre la ventana modal
            $(div).modal('open');   

        }

        // Hacer esto si la accion seleccionada es modificar
        if(button == "modificar") {
            // Si la cantidad de filas seleccionadas es mayor que 1
            if($scope.table.rows('.selected').data().length > 1) {
                $rootScope.alert("Error", "Solo puedes modificar un fila a la vez", "warning");
            // Si la cantidad de filas seleccionada es ninguna
            } else if ($scope.table.rows('.selected').data().length <= 0) {
                $rootScope.alert("Error", "Debes seleccionar un registro a modificar", "warning");
            // Si la cantidad de filas seleccionada es solo 1 (Solo se puede modificar una fila a la vez)
            } else {
                $(div).modal('open');


                $rootScope.get('api/' + $scope.obj_padre + '/' + $scope.clave_primaria).then(function(response) {
                    $scope.datos = response[0];
                }, function(response) {
                    console.log(response);
                });


            }
        }
    }
    
asked by Anthony Medina 14.04.2017 в 21:49
source

1 answer

0

I already solved my problem, apparently there is no error. I'm using Materialize and there seems to be a clash with the class and ng-repeat or angular ng-options.

Solve it this way

<select class="browser-default" ng-options="item as item.descripcion for item in tipo_de_tribunal track by item.id" ng-model="selected"></select>

I'm not happy because I wanted to use the materialize select class, but well, I see that is the error

    
answered by 14.04.2017 в 22:33