Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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访问ng模型_Javascript_Json_Angularjs - Fatal编程技术网

Javascript Angular无法从json访问ng模型

Javascript Angular无法从json访问ng模型,javascript,json,angularjs,Javascript,Json,Angularjs,我是angular和js的新手 请帮助我获取json密钥并绑定到ng模型 下面是我的代码 <div ng-app="myApp" ng-controller="customersCtrl"> <ul> <li ng-model="table.macid"></li> </ul> 这是我的plunker链接 非常感谢您的帮助,请提前感谢您可以将其转储到html中,如下所示: <li ng-model="table.

我是angular和js的新手 请帮助我获取json密钥并绑定到ng模型

下面是我的代码

<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
  <li ng-model="table.macid"></li>
</ul>
这是我的plunker链接


非常感谢您的帮助,请提前感谢

您可以将其转储到html中,如下所示:

      <li ng-model="table.macid"></li>{{table.macid}}
  • {{table.macid}

  • 这应该行得通,对我来说是这样的。您可能认为您看到了它,因为标记位于
  • 元素中。您希望它做什么?

    在li标记中使用ng repeat,如下所示:

    
    
    • {{macid}
    var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope,$http){ $scope.table={} $http.get(“test.json”) .成功(功能(响应){ $scope.names=响应 $scope.table.macid=Object.keys($scope.names.day.weekday.Monday.macu id) });console.log($scope.table) });
    您将
    ng型号
    ng绑定
    混淆:

    <div ng-app="myApp" ng-controller="customersCtrl">
    <ul>
      <li ng-bind="table.macid"></li>
    </ul>
    
    
    
    请参见


    如果需要迭代集合,请使用
    ng repeat
    。请参见zszep的答案。

    您不能在
  • 上使用
    ng模型。
    。我猜他想遍历集合。否则他为什么会使用列表项?这确实是一种可能性,这就是为什么我添加了这句话并让他参考你的答案。
    <!DOCTYPE html>
    <html>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    
    <body>
    
      <div ng-app="myApp" ng-controller="customersCtrl">
        <ul>
          <li ng-repeat="macid in table.macid">{{macid}}</li>
        </ul>
      </div>
    
    
      <script>
        var app = angular.module('myApp', []);
        app.controller('customersCtrl', function($scope, $http) {
          $scope.table={}
    
          $http.get("test.json")
            .success(function(response) {
    
              $scope.names = response
              $scope.table.macid= Object.keys($scope.names.day.weekday.Monday.mac_id)
    
            });console.log($scope.table)
        });
      </script>
    
    </body>
    
    </html>
    
    <div ng-app="myApp" ng-controller="customersCtrl">
    <ul>
      <li ng-bind="table.macid"></li>
    </ul>