3

I have a firebase setup application and need to get all documents in a collection before the related component render.

Data is coming through a normal subscription

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

But when I use a resolver like below, it does not resolve data or nothing happens.

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

  constructor(private db: DatabaseService) { }

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

}

service

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

routing

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

component

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

and registered my resolver in the root module and other non-firebase resolvers are working fine.

Why is this setup resolver not working?

version

firebase:4.11.0

angularfire2:^5.0.0-rc.6.0

angular:^5.2.0

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
SFernando
  • 1,074
  • 10
  • 35
  • Does this answer your question? [Resolver not returning Firestore's data to load a component in Angular](https://stackoverflow.com/questions/64518784/resolver-not-returning-firestores-data-to-load-a-component-in-angular) – dixavier27 Oct 31 '20 at 21:36

2 Answers2

0

Try this:

CHANGE:

return this.db.getCountryList();

TO:

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

As myself had troubles to get this, and maked such question as you did, I tryied somethings after perceive that the request is not endend by the resolver, so the keypoint to solve this is just to complete the request with a workaround pipe as I exposed in my question

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

dixavier27
  • 66
  • 8