Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Javascript 用angular和JSON填充下拉列表_Javascript_Angularjs_Json - Fatal编程技术网

Javascript 用angular和JSON填充下拉列表

Javascript 用angular和JSON填充下拉列表,javascript,angularjs,json,Javascript,Angularjs,Json,我有一个data.json文件,我想读取它并填写一个下拉列表。 我的代码是: <head> <script src="js/angular.min.js"></script> <script> MyPanel=angular.module('MyPanel',[]); MyPanel.controller('MyController', function($scope,$http){

我有一个data.json文件,我想读取它并填写一个下拉列表。 我的代码是:

 <head>
    <script src="js/angular.min.js"></script>
      <script>
        MyPanel=angular.module('MyPanel',[]);
        MyPanel.controller('MyController', function($scope,$http){
            $http.get('feed/data.json').success(function(response){
                $scope.myData = response;
            });
        });
      </script>
    </head>
<body ng-app="MyPanel" ng-controller="myController">
    <select ui-jq="chosen" id="storeId" class="form-control m-b" >
       <option value="">Choose</option>
       <option ng:repeat="data in myData">{{myData.id}} - {{myData.name}}</option>
    </select>
</body>

MyPanel=angular.module('MyPanel',[]);
控制器('MyController',函数($scope,$http){
$http.get('feed/data.json').success(函数(响应){
$scope.myData=响应;
});
});
选择
{{myData.id}-{{myData.name}
我没有用这个密码得到任何东西。没有错误,没有下拉列表。 你能帮我吗


谢谢

问题在这里:
ng:repeat
,应该是
ng repeat


顺便说一句,我强烈建议您使用
ng选项
,将代码更改为:

<option ng-repeat="data in myData"> {{data.id}} - {{data.name}}</option>
只是想看看我们实际上得到了一些数据

您还可以尝试创建一些测试数据

$scope.myData = [
    {id: 1, name: 'test1'},
    {id: 2, name: 'test2'} ];
同时注释掉
/$scope.myData=response


如果您的
ng repeat
与测试数据一起工作,那么您的问题不在于ng repeat,而在于
$http.get
请求

{{data.id}}-{data.name}
尝试使用insteadI尝试但不起作用。谢谢您设置
$scope.myData=response
后,您可以记录它吗?比如
console.log($scope.myData)只是看看你得到了什么样的响应这很奇怪。在chrome中可以加载列表,但在firefox中不会加载列表。我不明白为什么会这样
$scope.myData = [
    {id: 1, name: 'test1'},
    {id: 2, name: 'test2'} ];