2017-06-15 42 views
0

可以說我有:angularfire2,如何綁定到一個列表的路徑不同

this.arrUserSchools = this.db.list('/users/' + this.userKey + '/schools'); 

和我的模板:

<li *ngFor="let school of arrUserSchools | async" > 
    {{ school.name }} 
</li> 

到目前爲止,它的偉大工程。但是,如果this.userKey發生更改,我需要再次定義​​,雖然它可以正常工作,但每次更新列表時我都會看到整個html閃爍。

用新路徑再次設置this.arrUserSchools的正確方法是什麼?

+0

你是什麼意思的「整個HTML」? 「李」還是別的什麼? – acdcjunior

回答

0

那麼存在重新分配列表綁定沒有問題:

this.arrUserSchools = this.db.list('/users/' + this.userKey + '/schools'); 

的問題是,我是訂閱多次別處。 (newbie錯誤!)所以訂閱堆積在每次運行中,因此,重新分配包含要在模板上顯示的列表的數組多次。這是讓它「眨眼睛」

onFindUserByUid(uid: string) { 

    this.findUserByUidSubscription = this.db.list('/users', { 
    query: { 
     orderByChild: 'uid', 
     equalTo: uid 
    } 
    }).subscribe((snapshot) => { 
    // do stuff ... 
    this.findUserByUidSubscription.unsubscribe(); // <-- solution 
    }); 

} 
相關問題