firebase-如何使用rxjs划为拼写 - 最后的和平
我看到了这篇文章: Cloud Firestore-如何使用RXJS
这正是我需要的,但我不明白如何重现
import { UsersService } from '../../../shared/services/users.service';
我只需要理解此服务中的内容,因为我不能像getUsers()
和loadMoredata()
。我正在学习有关AngularFire的新模块化方法,上面的答案是我需要理解的方法才能正确实施分页。
到目前为止,我所做的事情:
import {
collection,
collectionData,
Firestore,
limit,
orderBy,
query,
startAfter
} from "@angular/fire/firestore";
querySnapshot:any;
lastInResponse:any;
constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
}
ngOnInit(): void {
this.stringEmitted.stringChanged(this.actualTitle);
this.loadCustomers('customers', 'name', 5)
}
loadCustomers(collectionName:string, order:string, max:number) {
return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
response => {
// @ts-ignore
this.lastInResponse = response[response.length - 1];
this.querySnapshot = response;
}
);
}
loadMore(data:object) {
return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(5), startAfter(data))).subscribe(
response => {
// @ts-ignore
this.lastInResponse = response[response.length - 1];
this.querySnapshot = this.querySnapshot.concat(response);
}
);
}
myTest() {
console.log(this.lastInResponse);
}
我只有这个代码错误firbaseError:function startafter()带有无效数据
的函数。函数myTest()
将从最后一个客户写入控制台的正确数据,但仍然出现错误。
正确的数据类型是什么?我该如何转换?
任何帮助将不胜感激!谢谢!
I saw this post: Cloud Firestore - How to paginate data with RXJS
This is exactly what I need but I don't understand how to reproduce the
import { UsersService } from '../../../shared/services/users.service';
I just need to understand what is inside this service because I can't make a function work like both getUsers()
and loadMoreData()
. I'm learning the new MODULAR approach on AngularFire and the answer above is the one I need to understand to properly implement pagination.
What I had done so far:
import {
collection,
collectionData,
Firestore,
limit,
orderBy,
query,
startAfter
} from "@angular/fire/firestore";
querySnapshot:any;
lastInResponse:any;
constructor( private stringEmitted: StringBridgeService, private firestore: Firestore ) {
}
ngOnInit(): void {
this.stringEmitted.stringChanged(this.actualTitle);
this.loadCustomers('customers', 'name', 5)
}
loadCustomers(collectionName:string, order:string, max:number) {
return collectionData(query(collection(this.firestore, collectionName), orderBy(order), limit(max))).subscribe(
response => {
// @ts-ignore
this.lastInResponse = response[response.length - 1];
this.querySnapshot = response;
}
);
}
loadMore(data:object) {
return collectionData(query(collection(this.firestore, 'customers'), orderBy('name'), limit(5), startAfter(data))).subscribe(
response => {
// @ts-ignore
this.lastInResponse = response[response.length - 1];
this.querySnapshot = this.querySnapshot.concat(response);
}
);
}
myTest() {
console.log(this.lastInResponse);
}
I only have ONE problem with this code ERROR FirebaseError: Function startAfter() called with invalid data
. The function myTest()
writes the correct data from the last customer to the console but still the error appears.
What is the right type of data? How could I convert?
Any help will be greatly appreciated! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法找到了解决方案!
startafter()
在我的情况下,我的列表上的姓氏要求。此处使用了True 模块化方法。谢谢大家!
I managed to find the solution!
startAfter()
requires, in my case, the last name on my list. The true modular approach was used here.Thank you all!