Поле mat-form-field должно содержать MatFormFieldControl

Согласно Документация Python 3.6

Возможно, что по умолчанию установка по умолчанию не устанавливается. Одно потенциальное исправление:

blockquote>
python -m ensurepip --default-pip

127
задан Kiran Maniya 30 September 2019 в 09:29
поделиться

3 ответа

Частичное решение состоит в том, чтобы перенести материальное поле формы в пользовательский компонент и реализовать эти ControlValueAccessor интерфейс на нем. Помимо проекции содержания эффект является в значительной степени тем же.

См. полный пример на Stackblitz.

я использовал FormControl ( реактивные формы ) в CustomInputComponent, но FormGroup, или FormArray должен работать также, если Вам нужен более сложный элемент формы.

app.component.html

<form [formGroup]="form" (ngSubmit)="onSubmit()">

  <mat-form-field appearance="outline" floatLabel="always" color="primary">
    <mat-label>First name</mat-label>
    <input matInput placeholder="First name" formControlName="firstName" required>
    <mat-hint>Fill in first name.</mat-hint>
    <mat-error *ngIf="firstNameControl.invalid && (firstNameControl.dirty || firstNameControl.touched)">
      <span *ngIf="firstNameControl.hasError('required')">
        You must fill in the first name.
      </span>
    </mat-error>
  </mat-form-field>

  <custom-input
    formControlName="lastName"
    [errorMessages]="errorMessagesForCustomInput"
    [hint]="'Fill in last name.'"
    [label]="'Last name'"
    [isRequired]="true"
    [placeholder]="'Last name'"
    [validators]="validatorsForCustomInput">
  </custom-input>

  <button mat-flat-button
    color="primary"
    type="submit"
    [disabled]="form.invalid || form.pending">
    Submit
  </button>

</form>

custom-input.component.html

<mat-form-field appearance="outline" floatLabel="always" color="primary">
  <mat-label>{{ label }}</mat-label>

  <input
    matInput
    [placeholder]="placeholder"
    [required]="isRequired"
    [formControl]="customControl"
    (blur)="onTouched()"
    (input)="onChange($event.target.value)">
  <mat-hint>{{ hint }}</mat-hint>

  <mat-error *ngIf="customControl.invalid && (customControl.dirty || customControl.touched)">
    <ng-container *ngFor="let error of errorMessages">
    <span *ngFor="let item of error | keyvalue">
      <span *ngIf="customControl.hasError(item.key)">
        {{ item.value }}
      </span>
    </span>
    </ng-container>
  </mat-error>
</mat-form-field>
1
ответ дан 24 November 2019 в 00:40
поделиться

если кто-либо попытается вложить <mat-radio-group> внутренняя часть <mat-form-field> как ниже, то Вы доберетесь, эта ошибка

         <mat-form-field>
                <!-- <mat-label>Image Position</mat-label> -->
                <mat-radio-group aria-label="Image Position" [(ngModel)]="section.field_1">
                    <mat-radio-button value="left">Left</mat-radio-button>
                    <mat-radio-button value="right">Right</mat-radio-button>
                </mat-radio-group>
            </mat-form-field>

удаляют родителя <mat-form-field> теги

0
ответ дан 24 November 2019 в 00:40
поделиться

Примечание Ошибка Некоторого времени происходит, когда мы используем тег "матового поля формы" вокруг кнопки отправки как:

<mat-form-field class="example-full-width">
   <button mat-raised-button type="submit" color="primary">  Login</button>
   </mat-form-field>

Настолько любезно не используют этот тег вокруг кнопки отправки

0
ответ дан 24 November 2019 в 00:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: