我有一个离子项目。
我希望取消订阅,当我从订阅firebase返回城市。
但是当我尝试取消订阅时出现问题并且它会引发跟随错误。
怎么解决这个问题?
我的代码。
getCities() {
let i: any;
let a = this.firebaseProvider.getOtoparks()
.subscribe(data => {
for (i = 0; i < data.length; i++) {
this.cities.push({
name: data[i]['details']['sehir'],
value: i,
}
);
}
// try to unsubscribe
a.unsubscribe();
});
}
最佳做法是在没有条件的情况下取消订阅时使用take(1)。
getCities() {
let i: any;
let a = this.firebaseProvider.getOtoparks()
.take(1)
.subscribe(data => {
for (i = 0; i < data.length; i++) {
this.cities.push({
name: data[i]['details']['sehir'],
value: i,
});
}
});
}