D
D
digiben2017-01-26 18:21:10
JavaScript
digiben, 2017-01-26 18:21:10

Angular 2 nested components and routes?

Good day, my dear friend.
I have the following problem: let's say there is the following application structure:

- AppComponent
-- TeamComponent
---  TeamMemberComponent
---- TeamMemberDetailsComponent.

The application has routes:
/
/team/:teamId
/team/:teamId/member/:memberId
/team/:teamId/member/:memberId/details

When requesting each route, a request is made to the api. The problem is that if the user navigates to the last route in the browser, an error may occur due to the fact that the parent component has not yet loaded. I would like to know how to solve this problem. One of the solutions I found is that for each route I need to create a resolver service, and write something like this in the routes
{
        path: 'team/:teamId',
        component: TeamComponent,
        resolve: {
            members: MembersResolverService
        },
        children: [
            ...
        ]
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nagaev, 2017-02-03
@mnagaev

if the child component requires data from the parent, then you probably need to make a preloader or hang *ngIf on the child component until the data in the parent is loaded and displayed.
Or get rid of such nesting of components

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question