Maximum Length in Angular TextArea Component

13 Jun 20241 minute to read

You can enforce a maximum length limit for the text input in the TextArea using the maxLength property. This property allows to define the maximum number of characters that users can input into the TextArea.

  • By setting the maxLength property, you can control the length of text input, preventing users from exceeding a specified character limit.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'



import { Component } from '@angular/core';

@Component({
imports: [
        
        TextAreaModule
    ],


standalone: true,
    selector: 'app-root',
    template: `<div class="wrap">
                <div class='textarea'>
                <ejs-textarea id="default" placeholder="Enter your comments" maxLength="20"></ejs-textarea>
                </div>
              </div>`
})

export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

When the user reaches the specified limit, the TextArea prevents further input, ensuring compliance with the defined character limit. This feature helps maintain data integrity and provides users with clear feedback on the allowed input length.