1

On my homepage I have a component that gets the top 3 latest posts from an API call:

<recent-posts></recent-posts>

Inside the .ts file I get the posts like so:

posts: Object;

const().......

this.posts = this.route.snapshot.data.data;

The call is made in the resolve:

path: '',
component: HomeComponent,
pathMatch: 'full',
resolve: { 
  data: RecentPostResolver
} 

Which has this code:

 resolve(): Observable<any> {
    return this.d.getItems('story', {limit: 3});
}

I want to be able to re-use this component on another page which will then get 6 latest posts.

I bound a parameter to a limit on the component like so

<recent-posts [limit]="6"></recent-posts>

and int he .ts for that component I added:

@Input() limit;

and in the ngOnit() to console log out the limit and whatever value I put in, it shows so that bit is working.

My questions is, How do I pass that passed in value to the Resolve so I can re-use this component to on many pages with different values?

4
  • 1
    seems that you need a parametric resolver, take a look here: stackoverflow.com/questions/50384242/… Commented May 10, 2019 at 14:48
  • Hey @Alessandro yes I saw that I could add data to the resolver. How do I get the limit set in the < recent-posts limit='3' > into that data. I am a little noobie so dont crucify apprentice. Commented May 10, 2019 at 14:54
  • After much googling it seems impossible to pass data from the component to the resolver. My next idea is to get all data from the resolver and filter in the component. Commented May 10, 2019 at 15:01
  • if fact you should not, your component seems to retrieve the post items from the router snapshot, which it is hydrated by your resolver, so it is the resolver that need to read the limit parameter from route data, and so you component remain agnostic Commented May 10, 2019 at 15:03

0

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.