gpt4 book ai didi

javascript - 我可以将 .then() 与 firebaseListObservable 一起使用吗,即 this.items = query 和 .then()

转载 作者:行者123 更新时间:2023-11-30 11:35:30 26 4
gpt4 key购买 nike

我想在 this.items 中加载所有消息后执行向下滚动的任务我正在使用 angularfire2

items: FirebaseListObservable<any[]>;

this.items = this.af.database.list('/conversations', {
query: {
orderByChild: 'chatKey',
equalTo: prop + '-' + this.userId
}
})

我想像下面这样使用,但它不起作用。

items: FirebaseListObservable<any[]>;

this.items = this.af.database.list('/conversations', {
query: {
orderByChild: 'chatKey',
equalTo: prop + '-' + this.userId
}
}).then(()=>{
this.scrollToBottom();
})

this.scrollTobottom 代码在下面并且适用于其他地方

  scrollToBottom(time?) {
setTimeout((data) => {
var element = document.getElementById('123');
element.scrollTop = element.scrollHeight - element.clientHeight;
console.log("element", element);
}, time ? time : 4000);

最佳答案

因为它是一个 Observable 对象,你必须要么使用

this.items = this.af.database.list('/conversations', {
query: {
orderByChild: 'chatKey',
equalTo: prop + '-' + this.userId
}
}).subscribe(data => {/* do things */}, error => {/* do error things */})

或者

this.items = this.af.database.list('/conversations', {
query: {
orderByChild: 'chatKey',
equalTo: prop + '-' + this.userId
}
})
.toPromise()
.then(/* ... */)

关于javascript - 我可以将 .then() 与 firebaseListObservable 一起使用吗,即 this.items = query 和 .then(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44646878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com