Angular Feature Modules
Create FModule:
ng generate module <module-name>
Output content:
app/
<module-name>/
<module-name>.module.ts
Copy the code
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class Module01Module { }
Copy the code
The output is as follows:
- Use the @NgModule decorator to decorate a Module class.
- CommonModule provides common directives such as ngIf,ngFor, and so on.
Import FModule into AppModule
@NgModule({imports: [Module01Module, // Add FModule], bootstrap: [AppComponent]}) export Class AppModule {}Copy the code
Render the component template of the FModule
- Add a component to an FModule
ng generate component <module-name>/<ComponentName>
- Angular’s modularity limits require an export from module A in case A non-A module uses A component from module A. The modified Module01 module is as follows:
@NgModule({ declarations: [ Comp1Component ], imports: [ CommonModule ], exports: [Comp1Component, // Export component]}) export class Module01Module {}Copy the code