Angular 中的app.module.ts

本文介绍了Angular中的根模块(@NgModule)及其使用,包括声明组件、导入其他模块如BrowserModule和FormsModule,以及配置服务和引导根组件(AppComponent)的过程。
摘要由CSDN通过智能技术生成
// 这是 angular 根模块, 告诉angular如何组装应用

// angular核心模块
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
// 浏览器解析模块
import {BrowserModule} from '@angular/platform-browser';

// 根组件
import {AppComponent} from './app.component';
import {HeaderComponent} from './components/header/header.component';
import {ComponentModuleComponent} from './components/component-module/component-module.component';
import {StorageService} from './services/storage.service';

// @NgModule装饰器,@NgModule接受一个元数据对象,告诉angular如何编译启动应用
@NgModule({
  declarations: [ // 配置当前项目运行的组件
    AppComponent,
    HeaderComponent,
    ComponentModuleComponent,
  ],
  imports: [ // 配置当前模块运行依赖的其他组件
    BrowserModule,
    FormsModule
  ],
  providers: [StorageService], // 配置项目所需要的服务
  bootstrap: [AppComponent] // 指定应用的主视图(称为根组件) 通过引导根AppModule来启动应用,这里一般写根组件
})
// 根模块不需要导出任何东西,因为其他组件不需要导入根模块
export class AppModule {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值