javascript - AngularJS Scope.Feed 循环

标签 javascript html angularjs cordova ionic-framework

如何使用 AngularJS 循环此数据?

在 Laravel 中,我可以在 HTML 中执行 var_dump,但我不熟悉 Angular。有关调试的任何建议以及如何循环它?

$scope.feed = 结果.data; enter image description here

.controller('FeedEntriesCtrl', function($scope, $stateParams, $http, FeedList, $q, $ionicLoading, BookMarkService) {
        $scope.feed = [];

        $scope.doRefresh = function() {
            $http.get("http://www.com/api/admin/v1/getListing?token=www")
                .then(function (result) {
                    $scope.feed = result;
                    console.log(result);
                    $ionicLoading.hide();
                    $scope.$broadcast('scroll.refreshComplete');
                }, function (reason) {
                    $ionicLoading.hide();
                    $scope.$broadcast('scroll.refreshComplete');
                });
        };

        $scope.doRefresh();

        $scope.bookmarkPost = function(post){
            $ionicLoading.show({ template: 'Post Saved!', noBackdrop: true, duration: 1000 });
            BookMarkService.bookmarkFeedPost(post);
        };
    })

最佳答案

Controller 中有两个用于获取列表的get请求。

 $http.get('http://www.com/api/admin/v1/getListing?token=www')

FeedList.get('http://www.com/api/admin/v1/getListing?token=wwww')

这里第二个请求发送第一个请求的成功响应。这不是必需的。从代码中删除一个请求。

其他事情是:

$scope.feed = result;

这里 result 分配给 $scope.feed 变量,因此您只能访问 DOM 中的 feed 对象,而不是数据变量。您正在尝试访问 ng-repeat

中的 data 对象

datafeed 的对象,因此您可以使用 .(dot) 属性进行访问。

feed.data

从图像中看不到id,但如果 id 是数组中的可用对象,则其余代码将正常工作。您只需将 ng-repeat

中的 data 更改为 feed.data
 <div class="list category-feeds">
      <a ng-repeat="source in feed.data" class="item item-icon-right" ui-sref="app.feed-entries({categoryId: source.id, sourceId: (source.id | slugify)})">
        <div class="thumbnail-outer">
          <pre-img ratio="_1_1" helper-class="">
            <img class="thumbnail" ng-src="{{source.id}}" spinner-on-load>
          </pre-img>
        </div>
        <div>
          <span class="title">{{source.id}}</span>
          <p class="description">{{source.id}}</p>
        </div>
      </a>
    </div

关于javascript - AngularJS Scope.Feed 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33138877/

相关文章:

javascript - 使用输入文本 Angular 克隆对象

javascript - 单击 [提交,操作] 按钮时显示模式

html - 简单的 css 定位(我认为)

javascript - 当我单击后退按钮时,它会将我带到我当前所在的同一页面

javascript - 在 Node 中插入新的 mongo 文档时保存不带 ObjectID 部分的 _id

javascript - 根据选择的单选按钮放大 h1

PHP - 如果变量不为空,则回显一些 html 代码

angularjs angular-file-upload 未知提供程序 : $uploadProvider error

javascript - 如何使用照片引用在 angularjs 中获取谷歌地点照片

javascript - 用多维数组制作下拉菜单