Angular Material 7 - 扩展面板

< mat-expansion-panel> ,Angular Directive,用于创建可扩展的详细信息v/s摘要视图.

  • < mat-expansion-panel-header> : 表示标题部分.包含面板摘要,并作为控件展开或折叠面板.

  • < mat-panel-title> : 代表小组标题.

  • < mat-panel-description> : 代表小组摘要.

  • < mat-action-row> : 表示底部的操作面板.

在本章中,我们将展示使用Angular Material绘制扩展控件所需的配置.

创建Angular应用程序

按照以下步骤更新我们在 Angular 6  -  Project Setup 章节中创建的Angular应用程序 :

Step描述
1 Angular 6  -  Project Setup 章节中的说明创建一个名为 materialApp 的项目.
2修改 app.module.ts app.component.ts app.component.css app.component.html ,如下所述.保持其余文件不变.
3编译并运行应用程序以验证实现的逻辑的结果.

以下是修改后的模块描述符的内容 app.module.ts .

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatExpansionModule, MatInputModule} from '@angular/material'
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
   declarations: [
      AppComponent
   ],
   imports: [
      BrowserModule,
      BrowserAnimationsModule,
      MatExpansionModule, MatInputModule,
      FormsModule,
      ReactiveFormsModule
   ],
   providers: [],
   bootstrap: [AppComponent]
})
export class AppModule { }


以下是修改过的HTML主机文件的内容 app.component.html .

<mat-expansion-panel>
   <mat-expansion-panel-header>
      <mat-panel-title>
         Personal data
      </mat-panel-title>
      <mat-panel-description>
         Type name and age
      </mat-panel-description>
   </mat-expansion-panel-header>
   <mat-form-field>
      <input matInput placeholder="Name">
   </mat-form-field>
   <mat-form-field>
      <input matInput placeholder="Age">
   </mat-form-field>
</mat-expansion-panel>


结果

验证结果.

扩展面板

详细信息

  • 作为第一个,我们使用mat-expansion-panel创建了扩展面板.

  • 然后,我们添加了标题,副标题和内容.