Programmatically Disable an Angular Email Material Input Field | Task

Ole Ersoy
Feb - 18  -  1 min

Scenario

We want the user to confirm their email address by entering a code.

We also want to use a disabled email reactive material input field so that it only shows the email address without any editing capability:

<mat-form-field>
    <input matInput placeholder="Email" type="email" formControlName="email">
</mat-form-field>

Approach

email = 'stephen@colbert.com';
confirm: FormGroup = new FormGroup({
email: new FormControl({value: this.email, disabled: true}),
code: new FormControl('', [ Validators.required, Validators.min(3) ])});

Demo