Angular Material Textarea Tutorial

Angular Material Textarea Tutorial

In this post we will give you information about Angular Material Textarea Tutorial. Hear we will give you detail about Angular Material Textarea TutorialAnd how to use it also give you demo for it if it is necessary.

Hello,

In this tutorial, i will show you angular material textarea example. This tutorial will give you simple example of angular mat textarea example. it’s simple example of angular material textarea reactive form. i would like to show you textarea angular material example. So, let’s follow few step to create example of angular 9/8 material textarea.

I’m going to show you about angular material mat-form-field for textarea reactive form. if you have question about angular material textarea example then i will give simple example with solution.

We can create material input textarea in angular 6, angular 7, angular 8 and angular 9.

I will give you two simple example with angular:

1) Basic Material Textarea

2) Material Textarea with Reactive Form

You can see bellow layout for demo:

Create New App

If you are doing example from scratch then You can easily create your angular app using bellow command:

ng new app-material

Add Material Design

Now in this step, we need to just install material design theme in our angular application. so let’s add as like bellow:

ng add @angular/material

Cmd like bellow:

Installing packages for tooling via npm.

Installed packages for tooling via npm.

? Choose a prebuilt theme name, or "custom" for a custom theme: Indigo/Pink

[ Preview: https://material.angular.io?theme=indigo-pink ]

? Set up global Angular Material typography styles? Yes

? Set up browser animations for Angular Material? Yes

Example 1: Basic Material Textarea

Here, we will create very simple example. first we need to import MatInputModule for mat-form-field for textarea material design. so let’s update app.module.ts, app.component.ts and app.component.html.

Let’s follow step:

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 Material Textarea Example</h4>

<mat-form-field >

<mat-label>Enter Note:</mat-label>

<textarea matInput placeholder="Ex. this is example..."></textarea>

</mat-form-field>

Example 2: Material Input Box with Reactive Form

Here, we will create very simple example using reactive form. first we need to import MatInputModule, MatButtonModule, FormsModule and ReactiveFormsModule for mat-form-field for textarea material design. so let’s update app.module.ts, app.component.ts and app.component.html.

Let’s follow step:

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 {MatButtonModule} from '@angular/material/button';

import {MatInputModule} from '@angular/material/input';

@NgModule({

declarations: [

AppComponent

],

imports: [

BrowserModule,

BrowserAnimationsModule,

FormsModule,

ReactiveFormsModule,

MatButtonModule,

MatInputModule

],

providers: [],

bootstrap: [AppComponent]

})

export class AppModule { }

src/app/app.component.html

<h1>Angular Material Textarea Example - ItSolutionStuff.com</h1>

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

<mat-form-field >

<mat-label>Enter Note:</mat-label>

<textarea matInput placeholder="Ex. this is example..." formControlName="note"></textarea>

<mat-error *ngIf="form.get('note').hasError('required')">

Email is <strong>required</strong>

</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({

note: ['', [Validators.required]],

})

}

get f(){

return this.form.controls;

}

submit(){

console.log(this.form.value);

}

}

You can easily run by following command:

ng serve

I hope it can help you…

Hope this code and post will helped you for implement Angular Material Textarea Tutorial. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  42  =  47

We accept paid advance and paid guest Posting on our Site : Contact US