3

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?

1

1 Answer 1

3

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.