0

I just started studying Angular (v11.0.2 in my source code), and I came across a behavior that I didn't understand.

The problem:

Clone app-structure and code in StackBlitz (major v10, behavior is the same):

see code (after loading, go manually to URL /workspace)

I trying to use SubcompComponent in WorkspaceComponent (see HTML-template), for lazy-loading WorkspaceModule (see AppRoutingModule and WorkspaceRoutingModule). Metadata selector is specified correctly. But I really can't understand what I'm doing wrong.

Q: Why is the component not loading?


What I tried to do:

  1. Adding SubcompComponent to declarations and exports in WorkspaceModule (see code workspace.module.ts)
  2. Also I tried use SharedModule (see workspace.module.ts too (commented line's)) as directed from the guide Sharing Modules
  3. Studied the main docs articles, including NgModule FAQ Lazy Loading NgModules and many others.

Probably, i'm not see the wood for the trees? Any ideas?


Additional:

Plese, suggest best practices for more detailed debugging (why a particular component is loaded now and when). So far, I only use Augury (Chromium) and write in VS Code.

Thank you in advance and excuse my English.

1 Answer 1

1

Working fork here https://stackblitz.com/edit/angular-ivy-jaxkll?file=src%2Fapp%2Fworkspace%2Fworkspace.component.html

  1. You have to have both components in your workspace module (you were not)

  2. You have to import your routing module as well (you were not)

    @NgModule({
      imports: [CommonModule,WorkspaceRoutingModule],
      declarations: [SubcompComponent,WorkspaceComponent],
      exports: [SubcompComponent]
    })
    export class WorkspaceModule {}
    
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it's work! But the second point is a bit unclear (You have to import your routing module). Сould you explain on your fingers why this is necessary? Maybe there is an explanation in the official documentation?
Your routes are defined as separate module WorkspaceRoutingModule and it was not imported into lazy loaded WorkspaceModule.
Oh, God, forgive my stupidity. Thank you very much!

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.