【问题标题】:Angular Material 2 Select Error Not Displaying Below ControlAngular Material 2 选择错误未显示在控件下方
【发布时间】:2018-06-21 18:51:53
【问题描述】:

Angular 4.4.4

Angular 材质 2.0.0-beta.12

我创建了一个带有以下mat-select 元素的模板驱动表单:

<mat-form-field class="add-task-full-width">
    <mat-select matInput
                [(ngModel)]="taskForCreation.areaId"
                id="areaControl"
                #areaControl="ngModel"
                name="areaControl"
                required
                (ngModelChange)="onAreaChanged($event)"
                placeholder="Area">
        <mat-option *ngFor="let area of areas" [value]="area.id">
            {{ area.description }}
        </mat-option>
        <mat-error *ngIf="areaControl.hasError('required')">
            Area is <strong>required</strong>
        </mat-error>
    </mat-select>
</mat-form-field>

如果我在未从列表中选择项目的情况下跳出字段,控件会变为红色并变为无效,但错误消息会显示在列表底部,而不是控件下方。无论我尝试什么,我都无法改变这一点。

谁能看看我哪里出错了?

【问题讨论】:

    标签: angular angular-material2


    【解决方案1】:

    mat-error 元素应放在mat-select 之外和mat-form-field 之内。请查看MatSelectform field features,了解有关如何在表单字段中使用它的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2018-06-02
      • 2019-01-20
      • 2016-12-08
      相关资源
      最近更新 更多