【发布时间】:2018-09-03 09:58:24
【问题描述】:
我像这样使用 Firestore。
用例 1:
contacts$: Observable<ContactDetail[]>;
constructor(){
}
ionViewDidEnter() {
this.contacts$ = this.contactProvider.getSpecificUserContacts(this.authenticationProvider.user.uid).valueChanges();
this.contacts$.pipe(first()).subscribe(res => { },
err => { },
() => { }
);
}
用例 2:
getAllContactCategories() {
this.categories$ = this.categoryProvider.getAllContactCategories().valueChanges();
this.categories$.subscribe(res => {
this.categorySortedList = res;
},
err => { }
);
}
但我从来没有unsubscribed它。那我需要这样做吗?否则会导致内存泄漏和耗尽电池使用量吗?
我知道我们不需要unsubscribed angular HTTP 服务,因为它是由框架本身自动完成的。那么 Firestore/Angularfire2 observables 呢?我从未在 Firestore 书籍或文章中看到过这样的模式。
【问题讨论】:
-
first()收到第一个值后自动退订.. -
好的,很高兴知道这件事。 用例 2 呢? @JeffreyRoosendaal
-
我对firestore一无所知,只是想指出
first()。take(N)和 `takeUntil(X) 这样的管道也是如此。 -
对于一般退订,请查看this post。它在选中的答案中为 Angular 提供了一个很棒的“官方”解决方案(
takeUntil()方法)
标签: angular firebase ionic3 google-cloud-firestore angularfire2