如何在Post上的Angular Firebase中实现喜欢/不喜欢的功能

时间:2018-10-27 13:36:13

标签: javascript angular firebase firebase-realtime-database

请帮助我解决这个问题。

我正在尝试在项目中喜欢“不喜欢”功能。我正在使用Angular 6和Firebase。问题出在我喜欢或不喜欢任何帖子并重新加载使用户向上滚动的所有提要时,快照更改或值更改。

检查下面的图像和我编写的代码。

enter image description here

this.userRef = this.db.list('xxxxxxxxx/feedmaster/');
      this.userRef.snapshotChanges(['child_changed'])
        .subscribe(actions => { 

          for(var i = (actions.length -1) ; i >= 0 ; i-- ){

             let feedkey = actions[i].key;
             let feedData =  actions[i].payload.val();
             let likebyself;
             let totallikekeys;
             if(actions[i].payload.val().likedby != undefined){

                totallikekeys = Object.keys(actions[i].payload.val().likedby);
                console.log( totallikekeys.includes(this.auth.userid));

                if( totallikekeys.includes(this.auth.userid)){

                  likebyself  = "text-success";

                }else{

                   likebyself = "text-muted";

                }

                console.log(likebyself);

            }else{

               likebyself = "text-muted";
               totallikekeys = [];
               console.log(likebyself);

             }
             self.timeLineFeed.length = 0;

               let textfeed = feedData.text;
               let posted_by = feedData.posted_by;
               let createdat = feedData.createdat;
               let updatedat = feedData.updatedat;  
               let posttype = feedData.content_type;

                this.db.object<User>(`xxxxxxxxxxx/users/${feedData.posted_by}/meta`).valueChanges()
               .subscribe( actions => {

                       //  this.feedwiseComment.length = 0;
                       console.log(likebyself);
                      // console.log(commentData);
                      if(actions.name != undefined && actions.name !="")
                      {
                      self.timeLineFeed.push({ feedkey:feedkey ,name:actions.name , picturUrl:actions.pictureURL, posttype:posttype, 
                        text:textfeed,posted_by:posted_by ,createdat : createdat , updatedat: updatedat , totallikes: totallikekeys.length , islikebyself: likebyself })

                      }

               } )
          }  
        })

0 个答案:

没有答案