Angular Feature Modules

Angular Feature Modules

创建FModule:

ng generate module <module-name>

输出内容:

app/
<module-name>/
<module-name>.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class Module01Module { }

输出内容说明:

  1. NgModule的用法和作用跟组件中的一致为了使用@NgModule装饰器来对Module类进行装饰.
  2. CommonModule的作用是提供了常用的指令如:ngIf,ngFor等.

将FModule导入AppModule

@NgModule({
imports: [
Module01Module, // 添加FModule
],
bootstrap: [AppComponent]
})
export class AppModule { }

渲染FModule的组件模板

  1. 为FModule模块增加组件 ng generate component <module-name>/<ComponentName>
  2. 受Angular模块化的限制,在非A模块去使用A模块中的组件的情况,需要在A模块中进行导出。修改后的module01模块如下:
    @NgModule({
    declarations: [
    Comp1Component
    ],
    imports: [
    CommonModule
    ],
    exports: [
    Comp1Component, // 导出组件
    ]
    })
    export class Module01Module { }
posted @   前端小鑫同学  阅读(6)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示