0

It's not another question about resolve I think. I would like to have simple, complex method to wait for Ajax data before rendering component in Angular 2. I will have about fifty routes, so creating resolve for each route would be pain.

Can someone share his way to wait for data before rendering view?

4
  • 1
    Not sure I got your question, but the really manual way to do it would be to set a flag such as isReady = true once your async call is complete and in the template wrap everything with <div *ngIf="isReady">...</div>. Or are you looking for something more involved? Commented Feb 13, 2017 at 17:55
  • you can use canActivate Commented Feb 13, 2017 at 17:55
  • 1
    I'm not sure I get the "I have 50 routes" part, though. If you do have 50 routes, you'll still have to do something 50 times. Whether you do that something inside a resolver or inside the component itself doesn't make a huge difference (as far of # of lines of code, I mean). Obviously you should avoid creating 50 unique resolvers; you could create a single generic resolver that examines the route, or better, some data param attached to the route, to decide which data it should load. Commented Feb 13, 2017 at 17:59
  • But will you agree, that creating for example one directive to handle all routes would be great. I think that someone hacked this problem in some smart way, smarter than I can imagine at this moment. Commented Feb 13, 2017 at 18:10

1 Answer 1

5
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.