javascript - AngularJS ng :repeat not working

标签 javascript php angularjs

我正在开发一个项目,在其中集成 WooCommerce API 在使用 AngualrJS 的移动应用程序中。

这里是the API它返回一个产品列表,这是我在其上实现 AngualrJS 的 HTML 页面。

问题是我无法在 HTML 页面上显示多个产品。

HTML 代码:

<div ng-app="myApp" ng-controller="productCtrl"> 
    <ul>
        <li>hello</li>
        <li ng:repeat="item in data">
            {{item.id}}  has children:  
        </li>
    </ul>
</div>

JS 文件:

var app = angular.module('myApp', []);
app.controller('productCtrl', function($scope, $http) {
    $http.get("http://www.ilexsquare.com/JwelTech/wordpress/api.php?function=GetProductsdetails")
    .then(function (response) {$scope.data = response.data;});      
});

这是我的 jsfiddle 代码 jsFiddle

最佳答案

只需更改您的 ng-repeat像这样:<li ng-repeat="item in data.products">

您的产品位于 key products 下在你的data 。请参阅下面的工作代码。

    var app = angular.module('myApp', []);
    app.controller('productCtrl', function($scope, $http) {
      $http.get("http://www.ilexsquare.com/JwelTech/wordpress/api.php?function=GetProductsdetails")
        .then(function(response) {
          $scope.data = response.data;
        });

    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="productCtrl">
  <ul>
    <li>hello</li>
    <li ng-repeat="item in data.products">
      {{item.id}}
    </li>
  </ul>
</div>

关于javascript - AngularJS ng :repeat not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34435604/

相关文章:

php - 将 ISSET 与复选框一起使用

javascript - AngularJS ng-仅包含一次

javascript - 使用nodejs和jade的Angular文件夹结构

angularjs - 如何替换 $http json 响应中字符串的每个实例

javascript - jQuery 返回多个函数

javascript - Chrome 无法在没有服务器的情况下设置 Cookie

php - Laravel 5.1 中未找到类错误

php - 有条件分组

javascript - 使用 ref 访问对象

javascript - 我怎样才能知道正在调用哪些函数?