ngInfiniteScroll resulting in TypeError: Cannot read property 'Scroll' of undefined

ngInfiniteScroll resulting in TypeError: Cannot read property 'Scroll' of undefined

我正在使用 Angular 与 Firebase 集成,我正在尝试在我的应用程序中实现无限滚动。

所以我很难使用 ngInfiniteScroll in my page. Following this documentation 我开始面临 TypeError: Cannot read property 'Scroll' of undefined angular.js:13236 错误消息。

(function (angular) {
  "use strict";

  var app = angular.module('myApp.baby', ['firebase', 'firebase.utils', 'firebase.auth', 'ngRoute', 'infinite-scroll']);

  app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/:babyId', {
        templateUrl: 'baby/baby.html',
        controller: 'BabyController',
    });
  }]);

  app.controller('BabyController', ['$scope', 'Auth', 'fbutil', 'FBURL', '$location', '$firebaseObject', '$routeParams', '$firebaseArray',
    function($scope, Auth, fbutil, FBURL, $location, $firebaseObject, $routeParams, $firebaseArray) {
      $scope.FBURL = FBURL;

      var unbind;

      var baby = $firebaseObject(fbutil.ref('babies', $routeParams.babyId));
      baby.$bindTo($scope, 'baby').then(function(ub) { unbind = ub; });

      var baseRef = new Firebase(FBURL).child("posts");
      var scrollRef = new Firebase.util.Scroll(baseRef, 'number');
      $scope.items = $firebaseArray(scrollRef);
      $scope.items.scroll = scrollRef.scroll;
    }
  ]);

})(angular);

posts.html

<div infinite-scroll="items.scroll.next(10)" infinite-scroll-distance="1">
  <div ng-repeat="item in items">
    {{item.$id}}: {{item.number}}, {{item.string}}
  </div>
</div>

我们将不胜感激。

这里的抱怨是 Firebase.util 未定义。最有可能的是,您未能通过脚本标记包含该库,或者您以错误的顺序包含了内容,并且在调用您的代码时它不可用。

问题中的代码未提供 mcve,错误与此处提供的代码无关,因此在回答此问题时涉及一些猜测。