Angular Material 7 - Card

< mat-card> ,Angular Directive,用于创建具有材料设计样式和动画功能的卡片.它为普通卡片部分提供预设样式.

  • < mat-card-title> : 代表标题的部分.

  • < mat-card-subtitle> : 代表副标题的部分.

  • < mat-card-content> : 表示内容部分.

  • < mat-card-actions> : 表示操作部分.

  • < mat-card-footer> : 表示页脚的部分.

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

创建Angular应用程序

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

Step描述
1创建一个名为 materialApp 的项目,如 Angular 6  -  Project Setup 章节中所述.
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 {MatCardModule, MatButtonModule} from '@angular/material'
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
   declarations: [
      AppComponent
   ],
   imports: [
      BrowserModule,
      BrowserAnimationsModule,
      MatCardModule, MatButtonModule,
      FormsModule,
      ReactiveFormsModule
   ],
   providers: [],
   bootstrap: [AppComponent]
})
export class AppModule { }

以下是修改过的CSS文件的内容 app.component.css .

.tp-card {
   max-width: 400px;
}
.tp-header-image {
   background-image: url('https://www.IT屋.com/materialize/src/html5-mini-logo.jpg');
   background-size: cover;
}

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

<mat-card class = "tp-card">
   <mat-card-header>
      <div mat-card-avatar class = "tp-header-image"></div>
      <mat-card-title>HTML5</mat-card-title>
      <mat-card-subtitle>HTML Basics</mat-card-subtitle>
   </mat-card-header>
   <img mat-card-image src = "https://www.IT屋.com/materialize/src/html5-mini-logo.jpg" alt = "Learn HTML5">
   <mat-card-content>
      <p>
         HTML5 is the next major revision of the HTML standard superseding
         HTML 4.01, XHTML 1.0, and XHTML 1.1. HTML5 is a standard for
         structuring and presenting content on the World Wide Web.
      </p>
   </mat-card-content>
   <mat-card-actions>
      <button mat-button>LIKE</button>
      <button mat-button>SHARE</button>
   </mat-card-actions>
</mat-card>

结果

验证结果.

卡

详细信息

  • 在这里,我们我们使用mat-card创建了一张卡片.