Form Text Box with Angular Material(mat-input) Example

Today, We want to share with you Form Text Box with Angular Material(mat-input) Example.In this post we will show you Angular 9 Material Text Box Example,mat-input in Angular, hear for Angular Material Form Controls, Form Field and Input Examples we will give you demo and example for implement.In this post, we will learn about Angular Textarea – Bootstrap 4 & Material Design with an example.

Form Text Box with Angular Material(mat-input) Example

There are the Following The simple About angular material input Full Information With Example and source code.

As I will cover this Post with live Working example to develop angular material form validation, so the mat-input-container is used for this example is following below.

Angular is a platform for building mobile & desktop web Based user friendly and light weight applications.Angular,It’s TypeScript-based open-source Angularjs web application framework.

Keywords : angular material text box, angular mat-form-field example, angular material mat-form-field input example, angular material input box example, angular material text field example

Make New App & Add Material Design

ng new app-material

ng add @angular/material

Example 1: Basic Material Input Box

src/app/app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatInputModule} from '@angular/material/input';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MatInputModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

src/app/app.component.html

<h4>Angular Input Box Example - www.pakainfo.com</h4>
<mat-form-field class="example-full-width">
    <mat-label>Name</mat-label>
    <input matInput placeholder="Ex. Ketan" value="Ketan">
</mat-form-field>
  
<mat-form-field class="example-full-width">
    <mat-label>Email</mat-label>
    <input matInput placeholder="Ex. [email protected]">
</mat-form-field>

Example 2: Material Input Box with Reactive Form

src/app/app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
  
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {MatInputModule} from '@angular/material/input';
import {MatButtonModule} from '@angular/material/button';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatInputModule,
    MatButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

src/app/app.component.html

<h1>Angular Material Input Box Example - Pakainfo.com</h1>
  
<form [formGroup]="form" (ngSubmit)="submit()">
  
  <mat-form-field class="example-full-width">
      <mat-label>Name</mat-label>
      <input matInput placeholder="Ex. Ketan" formControlName="name">
      <mat-error *ngIf="form.get('name').hasError('required')">
        Name Field is required
      </mat-error>
  </mat-form-field>
   
  <mat-form-field class="example-full-width">
      <mat-label>Email</mat-label>
      <input matInput placeholder="Ex. [email protected]" formControlName="email">
      <mat-error *ngIf="form.get('email').hasError('required')">
        Email Field is required
      </mat-error>
      <mat-error *ngIf="form.get('email').hasError('email')">
        Must be enter valid email
      </mat-error>
  </mat-form-field>
   
  <button mat-raised-button color="accent">Submit</button>
</form>

src/app/app.component.ts

import { Component } from '@angular/core';
  
import { FormBuilder, FormGroup, Validators} from '@angular/forms';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app-material2';
  
  form: FormGroup = new FormGroup({});
   
  constructor(private fb: FormBuilder) {
  
    this.form = fb.group({
      name: ['', [Validators.required]],
      email: ['', [Validators.required, Validators.email]],
    })
  }
    
  get f(){
    return this.form.controls;
  }
   
  submit(){
    console.log(this.form.value);
  }
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about angular material textarea example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Angular 6 CLI Installation Tutorial With Example
  2.   Confirm password validation in Angular 6|7|8|9
  3.   Decimal Pipe number Filter using Angular 9/8 Example
  4.   Angular KeyValue Pipe Example Tutorial
  5.   Angular 6 Smart Table with Sorting Searching and Pagination
  6.   AngularJS Confirm Password Validation Example
  7.   Bind DropdownList with Ng-Repeat using Angular Example
  8.   Angular 9/8 Select Dropdown | Get Selected DropDown Value on Change Event
  9.   Angular js Introduction to Looping Statements
  10.   Angular 9/8 Material Input Box Examples