我目前正在开发一个操作栏,其中包含几个按钮,这些按钮显示一些对当前数据进行过滤/排序的选项,但我在像其他元素一样调整元素的显示以获得良好的显示时遇到了困难.

enter image description here

这是我的动作栏,正如您在查看它时所预料的那样,我希望最后一个元素的图标与其他图标的高度相同,并且 Select 表单与其他元素的高度相同.

小澄清一下,每个按钮都会打开另一个组件的模板,例如,在下面的屏幕截图上,我点击了过滤器按钮,这就打开了过滤器组件模板.

这是我的代码:

动作栏模板:

<div class="container d-flex flex-wrap align-items-center justify-content-md-center">
  <app-export
  (outExport)="handleExport($event)"
  class="me-5">
  </app-export>

  <div *ngIf="showStats" class="me-5">
    <button type="button" class="btn btn-outline-secondary d-flex align-items-center" (click)="openStatsDialog()" data-bs-toggle="modal-dialog"><i class="bi bi-graph-up mx-1"></i> {{ "component.filter.filter.stats.title" | translate }}
    </button>
  </div>

  <app-display
  (outDisplayChange)="handleDisplayChange($event)"
  class="me-5">
  </app-display>

  <button class="btn btn-outline-secondary me-5" type="button" data-bs-toggle="collapse" data-bs-target="#filters" aria-expanded="false" aria-controls="filters"
  [ngClass]="{'active': filterOpened}" (click)="filterOpened = !filterOpened">
    <i class="bi bi-funnel"></i> {{ "component.filter.input.name" | translate }}
  </button>
  
  <button class="btn btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#sorts" aria-expanded="false" aria-controls="sorts"
  [ngClass]="{'active': sortOpened}" (click)="sortOpened = !sortOpened">
    <i class="bi bi-sort-alpha-down"></i> {{ "component.filter.filter.sorting.title" | translate }}
  </button>


</div>

<app-filter
    (outFilter)="handleFilter($event)"
    (outFilterAuthor)="handleFilterAuthor($event)"
    (outFilterTitle)="handleFilterTitle($event)"
    [docs]= "docs"
    class="me-5">
</app-filter>
    
<app-sort
    (outFilterOrder)="handleOrderFilter($event)"
    class="me-5">
</app-sort>

过滤器组件模板:

<div class="row collapse multi-collapse mt-4" id="filters">
    <div class="d-flex flex-wrap align-items-center">
        <div class="input-group me-3 col">
          <div class="input-group-prepend">
            <span class="input-group-text h-100"><i class="bi bi-pencil-square"></i></span>
          </div>
          <input #title type="text" class="form-control text-center" (input)="filtreTitre()" [placeholder]="'component.filter.input.title' | translate">
        </div>
      
          <div class="input-group me-3 col">
            <div class="input-group-prepend">
              <span class="input-group-text h-100"><i class="bi bi-person"></i></span>
            </div>
            <input #auth type="text" class="form-control text-center" (input)="filtreAuteur()" [placeholder]="'component.filter.input.author' | translate">
          </div>
      
          <div class="input-group col">
            <span class="input-group-prepend input-group-text h-100" style="align-self:flex-start;"><i class="bi bi-file-earmark"></i></span>
            <mat-form-field [formGroup]="filterGroup" appearance="fill">
              <mat-label>{{ "component.filter.input.doctype" | translate }}</mat-label>
              <mat-select multiple formGroupName="docType" (selectionChange)="onSelectionChange($event, 'docType', true)" [(value)]="selectedDocTypes">
                <ng-container *ngFor="let doc of docTypes">
                  <mat-option [value]="doc.code" *ngIf="doc.code !== 'POSTER'">{{ 'global.doctypes.' + doc.code | translate }}</mat-option>
                </ng-container>
              </mat-select> 
            </mat-form-field>
          </div>
    </div>
</div>

我已经try 将图标放入垫子形式字段中,但它效果不佳,我也try 使用 bootstrap 程序,但同样,它效果不佳(也许我做错了什么,所以欢迎任何建议).

更新:我try 使用mat-icon,因为我发现了名为"matPreFix/matSuffix"的东西,但似乎它不起作用.

推荐答案

这是包含您图标的标签:

<span class="input-group-prepend input-group-text h-100" style="align-self:flex-start;"><i class="bi bi-file-earmark"></i></span>

You should move this to inside your form field and add the matTextPrefix property to it (you might also remove the custom properties added).
Your code will look like this:

<mat-form-field [formGroup]="filterGroup" appearance="fill">
  <mat-label>{{ "component.filter.input.doctype" | translate }}</mat-label>
  <mat-select multiple formGroupName="docType" (selectionChange)="onSelectionChange($event, 'docType', true)" [(value)]="selectedDocTypes">
    <ng-container *ngFor="let doc of docTypes">
      <mat-option [value]="doc.code" *ngIf="doc.code !== 'POSTER'">{{ 'global.doctypes.' + doc.code | translate }}</mat-option>
    </ng-container>
  </mat-select> 
  <span matTextPrefix><i class="bi bi-file-earmark"></i></span>
</mat-form-field>

您可以在这里看到演示(带有美元符号): https://v16.material.angular.io/components/form-field/examples

如果您想要与示例不同的东西(具有不同的边界或背景),您可能还需要向其中添加额外的自定义属性,但我真的不建议使用棱角material 这样做.

Angular相关问答推荐

如何取回.angular/ache文件夹?

根据Angular中的构建来卸载独立组件

Angular:浏览器中未显示一些Google Content图标

如何在构造函数中测试MatDialog.Open

如何使用解析器处理Angular 路由中存储的查询参数以避免任何额外的导航?

如何从URL中角下载图片?

列表和映射的SCSS语法

一次重定向后,所有子路由都处于活动状态

无法绑定到formControl,因为它不是input的已知属性

大型 Angular 12 应用程序 - 我如何管理 js 文件

手动关闭 SSE 连接:Angular

Angular 测试被认为是成功的,即使有错误

Summernote 文本区域的输入字段文本验证失败

使用 RxJS forkJoin 时传递参数的最佳方式

缺少 .angular-cli.json 文件:Angular

Angular2 ngFor跳过第一个索引

Angular2 中的providers提供者是什么意思?

ERROR 错误:StaticInjectorError(AppModule)[UserformService -> HttpClient]:

如何使用 CLI 创建特定版本的 Angular 项目?

Angular 5 中 value 和 ngValue 的区别