可观察的混乱 [英] Observable Confusion
问题描述
我正在使用 Ionic2
与 AngularFire2
。
我也正在使用 在第二个函数中,可以看到我检索 我的问题是,因为这是一个 由于被删除的用户仍然在观察 错误:未被捕获(在promise中):错误:permission_denied在/ chat: 问题 有没有一种方法可以检索数据,而不会连接到 谢谢 这听起来像你想取消sribe从 您可以使用 I am using I am also making use of a and In the second function, you can see I retrieve the My problem is, because this is an It results in the following error because the deleted user is still trying to observe the Error: Uncaught (in promise): Error: permission_denied at /chat:
Client doesn't have permission to access the desired data. Error:
permission_denied at /chat: Client doesn't have permission to access
the desired data. Question Is there a way to retrieve the data, without still being attached to the Thanks It sounds like you want to unsubsribe from the You can use the
这篇关于可观察的混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! rxjs
Observable
。我有以下代码:
$ b $ pre $ findChatsForUid(uid:string):Observable< any []> {
return this.af.database.list('/ chat /',{
query:{
orderByChild:'negativtimestamp'
}
})。map (item => {
const filtered = items.filter(
item =>(item.memberId1 === uid || item.memberId2 === uid)
);
返回过滤;
});
code $
$ b $ p
$ pre> deleteChatsAndMessagesForUid(uid:string):Promise< any> {
return new Promise< any>((resolve)=> {
let promiseArray:Promise< any> [] = [];
this.findChatsForUid(uid).map(items forEach((chatItems)=> {
for(let i:number = 0; i< chatItems.length; i ++){
promiseArray.push(this.deleteChat(chatItems [i],true));
}
Promise.all(promiseArray).then(()=> {
resolve (true);
});
});
});
$ b $ p
$ b Observable
,并使用 forEach
函数循环遍历每个项目。
Observable
,总是有对象的句柄。所以,当我做到以下几点:$ b
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ code $ deleteChatsAndMessagesForUid(uid).then(()=> {
用户。 delete()。then(()=> {
...
}
}
Observable
,导致出现以下错误。
客户端没有访问所需数据的权限错误:
permission_denied at / chat:客户无权访问
所需的数据。
Observable
?这样我就可以自由删除关联的用户?还是有更好的方法来处理这个?
list
> observable在第一个发出的列表之后。
操作符在第一个发出列表之后完成 list
observable。这将导致自动取消订阅,并将侦听器从内部Firebase文档中移除。
$ b
import 'rxjs /添加/操作者/第一';
findChatsForUid(uid:string):Observable< any []> {
return this.af.database
.list('/ chat /',{
query:{
orderByChild:'negativtimestamp'
}
}}
.first()
.map(items => {
const filtered = items.filter(
item =>(item.memberId1 === uid | | item.memberId2 === uid)
);
return filtered;
});
}
Ionic2
with AngularFire2
.rxjs
Observable
. I have the following code:findChatsForUid(uid: string): Observable<any[]> {
return this.af.database.list('/chat/', {
query: {
orderByChild: 'negativtimestamp'
}
}).map(items => {
const filtered = items.filter(
item => (item.memberId1 === uid || item.memberId2 === uid)
);
return filtered;
});
}
deleteChatsAndMessagesForUid(uid: string): Promise<any> {
return new Promise<any>((resolve) => {
let promiseArray: Promise<any>[] = [];
this.findChatsForUid(uid).map(items => {
return items;
}).forEach((chatItems) => {
for (let i: number = 0; i < chatItems.length; i++) {
promiseArray.push(this.deleteChat(chatItems[i], true));
}
Promise.all(promiseArray).then(() => {
resolve(true);
});
});
});
}
Observable
from the first, and the loop through each item using the forEach
function.Observable
, there is always a handle to the object. So when I do the following:deleteChatsAndMessagesForUid(uid).then(() => {
user.delete().then(() => {
...
}
}
Observable
.
Observable
? So that I am free to delete the associated user? Or is there a better way to handle this?list
observable after the first emitted list.first
operator to complete the list
observable after the first emitted list. This will result in automatic unsubscription and the listeners will be removed from the internal Firebase ref.import 'rxjs/add/operator/first';
findChatsForUid(uid: string): Observable<any[]> {
return this.af.database
.list('/chat/', {
query: {
orderByChild: 'negativtimestamp'
}
})
.first()
.map(items => {
const filtered = items.filter(
item => (item.memberId1 === uid || item.memberId2 === uid)
);
return filtered;
});
}