Programmatically Disable an Angular Email Material Input Field

Updated Version

There is an updated version of this article here:

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

Brought to You By Firefly Semantics

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation