Mars Mars - 1 year ago 135
AngularJS Question

Angular ng-options display data from database

//EDIT Solution
the code its ok, the problem was materialize select, doesnt work with angular dinamic elements :(

Hello im trying to display data in a select tag with angular
i read a lot but i cannot solve this problem. as you can see with test code works but with the function does not, need help thanks

this is the json that php file returns


my controller

app.controller('chequeoCtrl', function($scope, $http){
//with this function do not work
$scope.leerNumero = function(){
$ = response.records;

// with this array works, just for test!!
/*$scope.names = [{"name":"pepe"},{"name":"pepe2"}];
console.log($scope.nombres); */



<select ng-model="autoelev" ng-options="item.numero as item.numero for item in data">
<option value="" disabled selected>Seleccionar autoelevador</option>

Answer Source

Try code below, Demo here:


<body ng-controller="MainCtrl">
  <select ng-options="item.numero for item in data" ng-model="chosen">
      <option value="" disabled selected>Seleccionar autoelevador</option>


angular.module('app', [])
  .controller('MainCtrl', function($scope, $http) {
      .then(function(res) {
        $ =;

Do $ = in your controller and make sure its an array of options.

console.log($ in your controller should print as below:

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