Skip to content

Importing

Alex Malkevich edited this page Feb 20, 2019 · 4 revisions

To use the library you need to import it's module.

You have to 2 options of doing this based on desired behavior:

  1. Use Angular's Router configuration for menu generation
  2. Manually provide all router configuration for menu generation

Case #1

Import as:

DynamicMenuModule.forRouter(extras?: DynamicMenuExtras)

Types: DynamicMenuExtras

extras.listenForConfigChanges = true by default

This will use Router from Angular to get router configuration. It will work just fine with one caveat - configuration from lazy loaded modules will not be available until it's module is loaded by Angular, which means that NOT whole menu subtree will be rendered.

However once the module is loaded - menu will be re-built and re-rendered with new information.

Case #2

Import as:

DynamicMenuModule.withRoutes(routes: RoutesWithMenu, extras?: DynamicMenuExtras)

Types: RoutesWithMenu, DynamicMenuExtras

This will use provided routes for menu. It is useful if you can resolve your routing configuration Ahead-of-Time so your lazy-loaded modules configuration is known at the beginning.

You can use ng-router-resolver to get your routing configuration as JSON file.


Now you are ready to render menu.

Clone this wiki locally