ngInfinite Scroll with AngularJS - Repeat $http



我试图使用ngInfinite Scroll来循环AngularJS$Http操作。我已经成功地使用1$Http pull运行了滚动,并加载了http://www.w3schools.com/angular/customers.php文件,但我想使用ngInfinite Scroll重新加载文件中的这15个值,我不确定如何将其放入"loadMore"函数中。因此,在初始加载时,从文件中提取完整的15个值。然后,当我向下滚动时,再次拉动它。谢谢

<div ng-app="myApp" ng-controller="customersCtrl">
    <div infinite-scroll='loadMore()'>
      <div ng-repeat="x in records">
        <p>{{ x.Name + ', ' + x.Country}}
      </div>
    </div>
</div>
var app = angular.module('myApp', ['infinite-scroll']);
app.controller('customersCtrl', function($scope, $http) {
  $http.get("http://www.w3schools.com/angular/customers.php")
    .success(function(data) {
      $scope.records = data.records;
      $scope.loadMore = function() {
          $http.get("http: //www.w3schools.com/angular/customers.php")
          .success(function(data) {
              $scope.records = data.records;
          });
      }
      });
});

在loadMore()函数中,我再次插入$Http请求,但它不起作用,所以我们非常感谢您提供的任何帮助!

有一些问题。CCD_ 1函数是在第一个CCD_。第二个问题是返回的数据取代了$scope.records,而不是添加到其中

var app = angular.module('myApp', ['infinite-scroll']);
app.controller('customersCtrl', function($scope, $http) {
  $http.get("http://www.w3schools.com/angular/customers.php")
    .success(function(data) {
      $scope.records = data.records;
  });
  $scope.loadMore = function() {
      $http.get("http: //www.w3schools.com/angular/customers.php")
      .success(function(data) {
          [].push.apply($scope.records, data.records);
      });
  }
});

最新更新