javascript - Angularjs not loaded data to select option -


i have select option need populate data database (json)

but not populate have correct json data

sample.html

<div class="form-group form-group-sm">     <label class="sr-only" for="inputdoctype">type</label>     <select aria-describedby="basic-addon1" class="form-control" ng-model="matin.type" ng-options="x.type x in data">         <option value="{{x.type}}">{{x.type}}</option>     </select> </div> 

controller.js

var xhr = $http({     method: 'post',     url: 'http://localhost/onseral/api/list-doctype.php' }); xhr.success(function(data){     console.log(json.stringify(data));     $scope.data = data.type; }); 

list-doctype.php

<?php  require_once '/config/dbconfig.php';  $table = (isset($_get['table'])) ? $_get['table'] : null;  getbyid($table);  function getbyid() {     $sql = "select distinct type min_in_head order type asc";     try {         $db = getdb();         $stmt = $db->prepare($sql);         $stmt->execute();         $data = $stmt->fetchall(pdo::fetch_obj);         $db = null;         echo json_encode($data);      } catch(pdoexception $e) {         echo '{"error":{"text":'. $e->getmessage() .'}}';     } } ?> 

console result

[{"type":"adj"},{"type":"wc in"}]

anyone know why?

first of json doesn't seem logical, have chnaged too:

{"type":["adj","cons out"]} 

but anyway, need use angular http service populating scope! this:

$http.post('http://localhost/onseral/api/list-doctype.php').then(function(res) {         $scope.matin= res.data;     }); 

Comments