jlgf
jlgf

Reputation: 307

Different template component in an application

I'm starting with angular and the next question comes up.

In the component, app.component.html is where I have a navigation and some more elements that are common to all routes. But now I want to create a part of the administrator that has to use neither the navigation nor the other elements. But others that I have created.

My question is: Can I create another file type "app.component" for the administration part with its own structure and that has nothing to do with the other party?

Upvotes: 0

Views: 143

Answers (1)

Pezetter
Pezetter

Reputation: 2862

You don't need another "app.component", you probably just want to create another module for admin utilities and routing. That way your app.component is just the parent for the whole application.

app.component will be in the main app.module.ts file, then you can create two child modules that are both imported into the app.module.

for example

  • app.module.ts (this has no entry components, just generic imports, including the child modules)
    • admin.module.ts
      • various components, directives, and services specific to the admin module
    • user.module.ts (I just picked "user" because it is generic)
      • various components, directives, and services specific to the "user" module

The point is to modularize sections of your application. That way your admin module can live separately from everything else and will not rely on any dependencies that the user.module does. And vice versa.

In addition, this opens up lazy loading options, specialized route guards per module, etc... I recommend reading over NgModules on the angular docs.

You'll notice at the end of that doc there are links for different module "types":

  • Feature Modules.
  • Entry Components.
  • Providers.

What you're asking for is two different feature modules with their own entry components and services

Upvotes: 1

Related Questions