0%

Angular中的模块

8.Angular中的模块

1. 创建自定义模块

1
2
3
4
ng g module 路径

创建带路由的模块
ng g module 路径 --routing

2. 使用自定义模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
e.g:
1. 创建自定义模块
ng g module modules/user --routing

2. 创建模块下子组件
ng g component modules/user/components/address

3. 创建模块根组件
ng g component modules/user

4. 在自定义模块中暴露出想在根组件中使用的子组件
@NgModule({
declarations: [模块下的子组件],
imports: [
CommonModule,
LiveChannelRoutingModule
],
exports:[想暴露出去的子组件]
})

5. 在根模块中导入自定义模块,即在app.module.ts文件中修改
import { 自定义模块 } from './live-channel/live-channel.module';

@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent,
MenuComponent
],
imports: [
BrowserModule,
AppRoutingModule,
自定义模块,
],
providers: [],
bootstrap: [AppComponent]
})