2

I work on Angular 10 project. I get data from my backEnd with a simple

return this.http
      .get<{ returned: Animal[] }>('animals')
      .pipe(map((res) => res.returned.map((value) => value)));

this is call by my resolver and send through router in my routing module with

resolve: {
        animals: AnimalResolver,
}

I get resolve data with this.route.snapshot.data.animals

I want to have an Obervable<Animal[]> for use AsyncPipe. The type return by the resolver is an Observable<Animal[]> but I get an error invalid Pipe argument, to resolve this error I need to make :

of(this.route.snapshot.data.animals);

Why?

Alphablony
  • 23
  • 1
  • 4
  • 1
    Before you start using resolvers a lot I'd recommend you to read this https://stackoverflow.com/questions/49054232/why-would-you-use-a-resolver-with-angular – maxime1992 Jul 28 '20 at 10:42

1 Answers1

2

In this case you need to use this.route.data observable where route is ActivatedRoute while ActivatedRouteSnapshot is just "static" data of current route and there are no observables here.

this.animals$ = this.route.data
  .pipe(map(data => data.animals));
vadimk7
  • 6,559
  • 1
  • 12
  • 15