markdown 角度 - 具有多输入场的材料形式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 角度 - 具有多输入场的材料形式相关的知识,希望对你有一定的参考价值。

# Angular - Form With Multiple Input Field

[SOURCE](https://loiane.com/2017/08/angular-reactive-forms-trigger-validation-on-submit/), [SOURCE](https://stackoverflow.com/a/14750390/1602807)

`contact-information.component.html`:

```html
<div id="ContactInput" fxLayout="column" [formGroup]="contactForm">
    <mat-form-field appearance="standard" fxFlex color="accent">
        <mat-label>{{'ContactInformation.customer_name_heading' | translate}}</mat-label>
        <input matInput [placeholder]="'ContactInformation.customer_name_heading' | translate"
               [formControlName]="customerInputName">
    </mat-form-field>
    <mat-form-field appearance="standard" fxFlex color="accent">
        <mat-label>{{'ContactInformation.patient_name_heading' | translate}}</mat-label>
        <input matInput [placeholder]="'ContactInformation.patient_name_placeholder' | translate"
               [formControlName]="patientInputName">
    </mat-form-field>
    <mat-form-field appearance="standard" fxFlex color="accent">
        <mat-label>{{'ContactInformation.phone_heading' | translate}}</mat-label>
        <input matInput [placeholder]="'ContactInformation.phone_heading' | translate"
               [formControlName]="phoneInputName">
    </mat-form-field>
    <mat-form-field appearance="standard" fxFlex color="accent">
        <mat-label>{{'ContactInformation.email_heading' | translate}}</mat-label>
        <input matInput [placeholder]="'ContactInformation.email_placeholder' | translate"
               [formControlName]="emailInputName">
    </mat-form-field>
</div>
<div fxLayout="row" fxLayoutAlign="center" id="ContinueButton">
    <button (click)="goToNextScreen()"
            class="btn-blue-width100-rounder"
            [title]="'ContactInformation.continue' | translate"
            [disabled]="!contactForm.valid">
        {{ 'ContactInformation.continue' | translate }}
    </button>
</div>
```

`contact-information.component.ts`:

```javascript
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
    selector: 'app-contact-information',
    templateUrl: './contact-information.component.html',
    styleUrls: ['./contact-information.component.scss']
})
export class ContactInformationComponent implements OnInit {
    private contactForm: FormGroup;
    private readonly customerInputName = 'customerFullNameInput';
    private readonly patientInputName = 'patientFullNameInput';
    private readonly phoneInputName = 'phoneNumberInput';
    private readonly emailInputName = 'emailInput';

    constructor(formBuilder: FormBuilder) {
        this.createForm(formBuilder);
    }

    ngOnInit() {
    }

    private createForm(formBuilder: FormBuilder) {
        this.contactForm = formBuilder.group({
            [this.customerInputName]: ['', Validators.required],
            [this.patientInputName]: '',
            [this.phoneInputName]: ['', Validators.required],
            [this.emailInputName]: ['', Validators.email],
        });
    }
}
```

For more validation see [Validation](https://angular.io/guide/form-validation).

以上是关于markdown 角度 - 具有多输入场的材料形式的主要内容,如果未能解决你的问题,请参考以下文章

markdown JHipster上的角度材料

角度材料数据表 - 如何为具有提前类型/自动完成搜索的列设置 filterPredicate?

角度材料 - mat-error 不显示输入字段的错误消息

角度材料日期选择器中的日期不正确

如何使用模板驱动形式将角度路由与角度材料步进器(https://material.angular.io/components/stepper/overview)结合起来?

使用 formcontrol 将数据绑定到角度材料表中的复选框。数据以真假值列表的形式提供