title: Get Data from Firebase In descending Order
body: <p>i need to get data from Firebase in descending order .</p>
  
  <p>When the component loads for the first time it happens fine.</p>
  
  <pre><code>  fetchData(){
      return this.af.list('/path/path/',{
        query: {
          orderByChild: 'createdAt'
        }
      }).map(arr =&gt; {return arr.reverse();});
    }
  </code></pre>
  
  <p>The data from fetch ads is stored in a var and then displayed.</p>
  
  <p>But now the problem is the var is modified at run time the user can update the var array , or delete or add to it . </p>
  
  <p>And when ever any of these operations takes place the data is modified on the firebase db and that calls the fetch data again .</p>
  
  <p>But then the reverse is again revesed rendering the whole thing use less.</p>
  
  <p>By this i mean is after the first component load the var is 1,2,3,4.
  But then when we add to var instead of becoming 1,2,3,4,5 it becomes 5,4,3,2,1.</p>
  
  <p>This is very confusing but i a tried lot but not able to fix this.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code> ngOnInit() {
  
      this.display = this.route.snapshot.data['Auth'];
  
      if(this.display){
        this.showProgress = true;
        this.user = JSON.parse(localStorage.getItem("user"));
        this.service.fetchData().subscribe((data) =&gt; {
          this.comments = data;
          this.showProgress = false;
        });
      } else {
        this.afAuth.authState.subscribe((data) =&gt; {
          if (data) {
            localStorage.setItem("user", JSON.stringify(data));
            this.user = data;
            this.service.fetchData().subscribe((res) =&gt; {
              this.comments = res;
              this.showProgress = false;
            });
          } else {
            this.comments = null;
          }
        });
  </code></pre>
  
  <p>This is what happens on run time rest all are the crud functions of angular2firebase that happens when we add update or delete</p>
  
  <p>I tried using pipes for the same but then it causes problem when getting the index so i dropped the plan as it was getting too complex</p>
  
  <pre><code>add(){
      this.service.postComment(this.comment, this.user);
    }
  
    editComment(key:string,updatedComment:any){
      const index = ((this.page-1)*5)+i;
      const updated = this.comments[index];
      updated.comment  = comment;
      this.service.editComment(updated.$key,updated);
    }
  
    deleteComment(key:String){
     this.service.deleteComment(this.comments[index].$key);
    }
  </code></pre>