【问题标题】:ngInfiniteScroll resulting in TypeError: Cannot read property 'Scroll' of undefinedngInfiniteScroll 导致 TypeError:无法读取未定义的属性“滚动”
【发布时间】:2016-02-27 22:21:29
【问题描述】:

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

所以我很难在我的页面中使用ngInfiniteScroll。关注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>

我们将不胜感激。

【问题讨论】:

  • 数据是否与您的 ng-repeat 一起显示?
  • @comoss 不,屏幕上什么也没有发生。

标签: angularjs firebase angularfire nginfinitescroll


【解决方案1】:

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

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

【讨论】:

  • 好的,还有什么可以包含在这里? included things in wrong order 是什么意思?首先或最后应该包括什么?
  • 如果您不知道&lt;script&gt; 标签是什么或如何包含它们,我不会在这里提供太多帮助。 Firebase.util 在您尝试使用它时不存在。为了让它存在,你必须包含它,并且在你尝试使用它之前你必须这样做。
猜你喜欢
  • 2022-01-15
  • 1970-01-01
  • 2020-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
相关资源
最近更新 更多