gpt4 book ai didi

angular - 无法使用 firestore 解析数据

转载 作者:行者123 更新时间:2023-12-05 01:31:14 24 4
gpt4 key购买 nike

我有一个 firebase 设置应用程序,需要在相关组件呈现之前获取集合中的所有文档。

数据来自普通订阅

this.db.getCountryList().subscribe(countryList => this.countryList = countryList); //working, I have the country list now

但是当我使用像下面这样的解析器时,它不解析数据或者什么也没有发生。

@Injectable()
export class CountryListResolver implements Resolve<Country[]> {

constructor(private db: DatabaseService) { }

resolve(): Observable<Country[]> {
return this.db.getCountryList();
}

}

服务

getCountryList(): Observable<Country[]> {
return this.db.collection<Country>(this.countryPath,ref => ref.orderBy('name', 'asc')).valueChanges();
}

路由

{ path: 'geo', component: GeographicalDataComponent, resolve: {countryList: CountryListResolver } },

组件

this.route.data.subscribe(data => {
this.countryList = data['countryList'];
});

并在根模块中注册了我的解析器,其他非 firebase 解析器工作正常。

为什么这个设置解析器不起作用?

版本

火力基地:4.11.0

angularfire2:^5.0.0-rc.6.0

Angular :^5.2.0

最佳答案

试试这个:

改变:

return this.db.getCountryList();

收件人:

const doc = this.db.getCountryList().toPromise();
return doc.then(data => {
return data;
});

关于angular - 无法使用 firestore 解析数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50076722/

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