2016-05-29 12 views
4

基本的に私は$ firebaseArrayという投稿を持つタイムラインを持っており、この配列への変更は正しくバインドされています。しかし、他のデータをバインドしたいときは、ngInfiniteScrollがfirebaseからより多くのデータを取得しようとしているときだけバインドします。角度バインディングはngInfiniteScrollと正しく動作しません

私は{{getMoreDetails()}}というコードを呼び出しています。このデータは、最初のデータセットがngInfiniteScrollで取得されたときにバインドされ、バインドブレークが読み込まれ、スクロール時に再度バインドされるとバインドされます。ここ

私の懸念は、以下のとおりです。

  • ngInfiniteScrollこのように動作するように設計されましたか?
  • このシナリオでは、回避策はありますか?

スタック:

"firebase": "2.4.2","angularfire": "~1.2.0","firebase-util": "0.2.5","ngInfiniteScroll": "1.2.2" 

timeline.html

<div ng-controller="TimelineController"> 
    <section class="entrys main-content" infinite-scroll="posts.scroll.next(3)" infinite-scroll-distance="0.3"> 
     <div class="inner"> 
      <div ng-repeat="post in filteredPostsResults = (posts | filter:postIdFilter)"> 
       <article class="entry"> 

        <img ng-if="post.sourceType=='IMAGE'" data-ng-src="{{getPostData(post)}}"/> 

        <div class="entry-info"> 
         <h3><div ng-bind-html="post.description | emoticons"></div></h3> 
         <small>posted on <time>{{getDateInFormat(post.createdAt)}}</time></small> 
         {{getMoreDetails()}} 
        </div> 

       </article> 
      </div> 
     </div> 
    </section> 
</div> 

timeline.js

(function (angular) { 
     "use strict"; 

     var timeline = angular.module('myApp.user.timeline', ['firebase', 'firebase.utils', 'firebase.auth', 'ngRoute', 'myApp.user.timelineService']); 

     timeline.controller('TimelineController', [ '$scope', '$routeParams', 'TimelineService', '$publisherServices', '$securityProperties', function ($scope, $routeParams, TimelineService, $publisherServices, $securityProperties) { 

      if (!$scope.posts){ 
       $scope.posts = TimelineService.getPosts($routeParams.userId); 
      } 
      $scope.posts.$loaded(function(result) { 
       $scope.isPostsLoaded = true; 
      }); 


      $scope.getMoreDetails = function() { 
       console.log("LOGGED ONLY WHEN SCROLLING"); 
       return $publisherServices.getDetails(); 
      }; 

      $scope.getPostData = function(post) { 
       if (!post.dataUrl){ 
        post.dataUrl = $publisherServices.getAwsFileUrl(post.fileName); 
       } 
       return post.dataUrl; 
      }; 

      $scope.postIdFilter = function(post) { 
       if ($routeParams.postId){ 
        if (post.$id == $routeParams.postId) return post; 
       } else { return post; } 
      }; 

      $scope.getDateInFormat = function(timestamp){ 
       var date = new Date(); 
       date.setTime(timestamp); 
       return date; 
      }; 

     }]); 

    })(angular); 

timelineService.js

(function (angular) { 
     "use strict"; 

    var timelineService = angular.module('myApp.user.timelineService', []); 

    timelineService.service('TimelineService', ['$routeParams', 'FBURL', '$firebaseArray', function ($routeParams, FBURL, $firebaseArray) { 
     var posts; 
     var currentUserIdPosts; 
     var postsRef; 

     var self = { 
      getPosts: function(userId){ 
      if (!posts || userId != currentUserIdPosts){ 
       currentUserIdPosts = userId; 
       postsRef = new Firebase(FBURL).child("posts").child(userId); 
       var scrollRef = new Firebase.util.Scroll(postsRef, "createdAtDesc"); 
       posts = $firebaseArray(scrollRef); 
       posts.scroll = scrollRef.scroll; 
      } 
      return posts; 
      } 

     } 
     return self; 
     }]); 

    })(angular); 
+0

バインディングはinitで動作しますか?下にスクロールするまで更新されませんか?それとも、まったく動かないのですか? –

+0

投稿の詳細が更新されることを期待するイベントはありますか?下にスクロールするまで、あなたのアプリはダイジェストサイクルを実行していないようです。 –

+0

@ buggy1985返信ありがとうございます。私のバインディングはinit上で動作し、firebaseの初期データがngInifiniteScrollで取得されるとすぐに、スクロールしてより多くのデータを取得するときにのみバインドされます。 'getMoreDetails()'はfirebase配列から来ていません。別のサービスから別のデータを取得しています。要点は、全く呼び出されていないということです。 'console.log'は私がisntログを呼び出そうとしています。 – adolfosrs

答えて

3

Firebaseのデータが変更されたときに投稿の詳細が更新されることを前提としています。

Firebaseの変更がスコープに適用されると、ダイジェストサイクルが開始されないようですので、Firebaseからアップデートを入手するたびに手動で行う必要があります。

$$updated$firebaseArray.$extendsee docs)で見てください。

// now let's create a synchronized array factory that uses our Widget 
app.factory("WidgetFactory", function($firebaseArray, Widget) { 
    return $firebaseArray.$extend({ 

    // override the update behavior to call Widget.update() 
    $$updated: function(snap) { 
     // we need to return true/false here or $watch listeners will not get triggered 
     // luckily, our Widget.prototype.update() method already returns a boolean if 
     // anything has changed 
     return this.$getRecord(snap.key()).update(snap); 
    } 
    }); 
}); 

私はこのことができます願っています。

関連する問題