liveBook · Manning

Exports property

As explained in Pro Angular 16

The exports property is Angular module metadata listing declarations or imported features made available to other Angular modules.

The exports property in @NgModule metadata defines which declared components, directives, pipes, or imported modules a feature module makes available to modules that import it. Exported classes must already appear in declarations or imports. section 19.3.2

Exporting a feature component

A store feature module declares StoreComponent and exports it so the root module can use the component after importing StoreModule: @NgModule({ imports: [ModelModule, BrowserModule, FormsModule], declarations: [StoreComponent], exports: [StoreComponent] }) export class StoreModule { } The declarations property makes StoreComponent available inside the feature module; exports extends that availability to importing modules. section 5.4.2

Use the exports property to:

  • Expose selected components, directives, and pipes from a feature module. section 19.3.2
  • Re-export an imported module type when that module is already listed in imports. section 19.3.2
  • Reduce direct imports of shared declarations after consolidating them in a common module. section 19.3.2
Listing 5.17. The contents of the store.module.ts file in the src/app/store folder
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { ModelModule } from "../model/model.module";
import { StoreComponent } from "./store.component";
 
@NgModule({
    imports: [ModelModule, BrowserModule, FormsModule],
    declarations: [StoreComponent],
    exports: [StoreComponent]
})
export class StoreModule { }

Inspect the complete store.module.ts listing showing imports, declarations, and exports together. section 5.4.2

How Pro Angular 16 covers it

How deep it goes
Explains availability rules and declaration/import prerequisites, then demonstrates a complete StoreComponent configuration.
Examples
Uses StoreComponent in StoreModule and shared directives, pipes, and services in a common module.
What it assumes
Assumes familiarity with @NgModule metadata while clarifying how declarations and imports prepare exports.
What you can do after
Configure an Angular feature module that exposes selected declarations to its importing modules.
How it connects
Connects @NgModule metadata with declarations, imports, feature modules, and shared modules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.