开发学院

您的位置:首页>教程>正文

教程正文

Angular Material 7 工具栏

  <mat-toolbar>用于创建以显示标题、标题或任何操作按钮的工具栏。

  <mat-toolbar> -代表主容器。

  <mat-toolbar-row> -添加新行。

  在本章中,我们将展示使用Angular Material绘制工具栏控件所需的配置。

创建 Angular 应用

  按照以下步骤创建应用程序

  1.创建一个名为materialApp的项目。

  2.修改app.module.ts, app.component.ts, app.component.css and app.component.htmls。保持其余文件不变。

  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 {MatToolbarModule} from '@angular/material'
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
   declarations: [
      AppComponent
   ],
   imports: [
      BrowserModule,
      BrowserAnimationsModule,
      MatToolbarModule,
      FormsModule,
      ReactiveFormsModule
   ],
   providers: [],
   bootstrap: [AppComponent]
})
export class AppModule { }

  下面是修改后的app.component.css文件内容。

.filler {
   flex: 1 1 auto;
}
.gap {
   margin-right: 10px;
}

  下面是修改后的 app.component.html文件内容。

<mat-toolbar color = "primary">
   <span class = "gap">File</span>
   <span>Edit</span>
   <span class = "filler"></span>
   <span>About</span>
</mat-toolbar>

结果

angular_material7_toolbar.jpg

细节

  首先,我们创建了一个横跨整个页面的工具栏。

  然后添加了标签。