【问题标题】:can not resolve data with firestore无法使用 Firestore 解析数据
【发布时间】:2018-04-28 12:49:56
【问题描述】:

我有一个 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

角度:^5.2.0

【问题讨论】:

标签: angular firebase observable google-cloud-firestore angular-resolver


【解决方案1】:

试试这个:

改变:

return this.db.getCountryList();

到:

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

【讨论】:

    【解决方案2】:

    由于我自己很难得到这个,并且像你一样提出了这样的问题,我在发现请求不是由解析器结束后尝试了一些东西,所以解决这个问题的关键就是用解决方法完成请求管道正如我在问题中所揭示的那样

    https://stackoverflow.com/a/64582997/3923628

    【讨论】:

    • 要么将其标记为重复,要么将答案也复制到此处?
    猜你喜欢
    • 2019-01-24
    • 2019-02-09
    • 1970-01-01
    • 2019-04-13
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    相关资源
    最近更新 更多