Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将JSON数据获取到angularJS模块_Php_Mysql_Angularjs_Json - Fatal编程技术网

Php 将JSON数据获取到angularJS模块

Php 将JSON数据获取到angularJS模块,php,mysql,angularjs,json,Php,Mysql,Angularjs,Json,我正在尝试将json数据绑定到angular模块。下面是我的代码 <script> var app = angular.module('myApp',[]); app.controller('myCtrl',function($scope,$http){ $http.get("list.php").then(function(response) { $scope.myData = response.data.records; }); })

我正在尝试将json数据绑定到angular模块。下面是我的代码

<script>
  var app = angular.module('myApp',[]);
  app.controller('myCtrl',function($scope,$http){
    $http.get("list.php").then(function(response) {
        $scope.myData = response.data.records; 
    });
  });
</script> 

    <div class="col-md-12"><!--col 1-->
       <ul>
        <li ng-repeat="z in myData">
          {{ z.Type }}
        </li>
      </ul>

var-app=angular.module('myApp',[]);
app.controller('myCtrl',函数($scope,$http){
$http.get(“list.php”).then(函数(响应){
$scope.myData=response.data.records;
});
});
  • {{z.Type}
和我的list.php文件

<?php    
include_once("mysql_db/db.php");
$sql = "SELECT * FROM taxitype";
$data = retrieve($sql); // This execute mysqli functions and return an array
echo json_encode($data);  
?>

但它现在正在HTML文件中显示列表。原因可能是什么?
他们有没有为angularJS创建json对象的特殊方法?

您应该编写
response.data
,而不是
response.data.records
。因为JSON是一个
数组
而不是
对象

请参阅
$http
服务

这是您的更新代码

<script>
  var app = angular.module('myApp',[]);
  app.controller('myCtrl',function($scope,$http){
    $http.get("list.php").then(function(response) {
        $scope.myData = response.data; 
    });
  });
</script> 

    <div class="col-md-12"><!--col 1-->
       <ul>
        <li ng-repeat="z in myData">
          {{ z.Type }}
        </li>
      </ul>

var-app=angular.module('myApp',[]);
app.controller('myCtrl',函数($scope,$http){
$http.get(“list.php”).then(函数(响应){
$scope.myData=response.data;
});
});
  • {{z.Type}

你能粘贴你的JSON,它通过你的API返回吗?[{“code”:“1”,“Type”:“Luxuary”,“MinFee”:“2000.00”,“DayRate”:“50.00”},{“code”:“2”,“Type”:“sample”,“MinFee”:“300.00”,“DayRate”:“200.00”},{“code”:“3”,“Type”:“Economy”,“MinFee”:“2000.00”,“DayRate”:“45.00”},{“code”:“code”:“4”,“Type”:“sdf”,“MinFee”:“456“sfdsdfsdf”、“MinFee”:“2323.00”、“DayRate”:“2323.00”}]