how to load a select with data coming from an API with AngularJS

1

Good evening, I'm not able to load a select on angularJS! It does not load, it goes blank. I'll post the code, if anyone can help me thank you !! Controller:

<script>
    angular.module("cadastroMedico", []);
    angular.module("cadastroMedico").controller("cadastroMedicoController", function ($scope, $http){
      $scope.app = "Cadastro de paciêntes";
      $scope.pacienteEspe = [
      ];

      var pacienteEspecial = function (){

      $http.get("http://localhost:27623/api/amb/Diseases/TESTES%20CUTANEOS%20DE%20LEITURA%20IMEDIATA").then(function (data) {
           $scope.pacienteEspe = data;
           console.log(data);
       }); 


      };

      pacienteEspecial();

    });
  </script>

index.html:

 <select class="form-control" ng-model="paciente.pacienteEspe" ng-options="pacienteEsp.Procedimento_tuss for pacienteEsp in pacienteEspe">
             <option value="">Selecione uma opcão</option>
           </select>

It does not load, it looks as if the data is there, but it does not have anything! I've tried everything .. If anyone can help ..

Thanks!

Returnonconsole:

    
asked by anonymous 06.06.2017 / 04:23

1 answer

2

In an initial analysis it seems to me that your code has no problem. What may be happening is that your application is not initializing properly.

Below is your code in functional state, with preloaded data and a view for iteration with controller :

angular.module("cadastroMedico", [])
    .controller("cadastroMedicoController", function($scope) {
        $scope.app = "Cadastro de pacientes";
        $scope.pacienteEspe = [
            {
                "Id_amb92": 79,
                "Cod_amb92": "19010117",
                "Procedimento_amb92": "TESTES CUTANEOS DE LEITURA IMEDIATA",
                "Cod_tuss": "41401425",
                "Procedimento_tuss": "TESTES DE CONTATO - ATÉ 30 SUBSTÂNCIAS",
                "Ch": "60"
            }
        ];
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script><divng-app="cadastroMedico">

  <div ng-controller="cadastroMedicoController">
    <select class="form-control" ng-model="paciente.pacienteEspe" ng-options="pacienteEsp.Procedimento_tuss for pacienteEsp in pacienteEspe">
     <option value="">Selecione uma opcão</option>
    </select>
    <pre>{{paciente | json}}</pre>
  </div>
</div>
    
06.06.2017 / 15:13