2

I have select option code:

<select ng-init="loadHouse()" name="house" ng-model="house" class="form-control">  
 <option value="">Select House</option>  
 <option ng-repeat="house in houses" value="{{house.hid}}">{{house.hname}}</option>  
</select> 

Script:

$scope.loadHouse = function(){
 $http.get("Unity/load_house.php")  
 .then(function(data){
  $scope.houses = data;  
  console.log(data);
 })  
}

And load_house.php

include('../config/config.php');
require 'model/model.unity.php';
$insertHouse = loadHouses();
while($row = mysqli_fetch_array($insertHouse)){  
  $output[] = $row;  
}  
echo json_encode($output);

It seems to work and I am able to print data inside console. But inside option its empty:

enter image description here

What can be the problem?

EDIT Here is console data:

enter image description here

2 Answers2

1

You need to use data.data

$scope.loadHouse = function(){
 $http.get("Unity/load_house.php")  
 .then(function(data){
  $scope.houses = data.data;  
  console.log(data);
 })  
}

also use ng-options instead of ng-repeat as follows

<select ng-options="item as item.hcolor for item in houses" ng-model="selected"></select>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

you should define scope of houses, outside of loadHouse function try this.

$scope.houses = [];
$scope.loadHouse = function(){
  $http.get("Unity/load_house.php")  
   .then(function(data){
     $scope.houses = data;  
     console.log(data);
   })  
}

and your ng-model of select should different then ng-repeat local scope of house, try this

ng-repeat="_house in houses"
Praveen Soni
  • 771
  • 8
  • 21