When using a FirebaseListObservable with an AngularFire2 database list and NgFor in my template i get duplicate rows.
TS
import { Component } from ‘@angular/core’;
import { NavController, NavParams } from ‘ionic-angular’;
import firebase from ‘firebase’;
import {AngularFire, FirebaseListObservable} from ‘angularfire2’;
import { LoadingProvider } from ‘…/…/providers/loading’;
import { GroupAddPage } from ‘…/group-add/group-add’;
/*
Generated class for the Chats page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-chats',
templateUrl: 'chats.html'
})
export class ChatsPage {
groups: FirebaseListObservable<any>;
people: FirebaseListObservable<any>;
userProfile: any;
chatType: string = "groups";
constructor(public navCtrl: NavController, public navParams: NavParams, af: AngularFire) {
this.groups = af.database.list('/Groups');
this.people = af.database.list('/userProfile/');
}
ionViewDidLoad() {
console.log('ionViewDidLoad ChatsPage');
}
goToGroupAddPage(){
this.navCtrl.push(GroupAddPage);
}
}
HTML
<ion-list *ngSwitchCase=“‘people’”>
<ion-searchbar>
[(ngModel)]="peopleSearch"
[showCancelButton]="shouldShowCancel"
(ionInput)="searchPeople($event)"
(ionCancel)="onCancel($event)">
</ion-searchbar>
<ion-item color = "amethyst-reverse" detail-push *ngFor="let person of people | async" (click)="goToPersonChat(person)">
<ion-avatar item-left>
<img src={{person.photoURL}}>
</ion-avatar>
<h2>{{person.firstname}} {{person.lastname}}</h2>
</ion-item>
</ion-list>