Angular2 maxLength for textarea as variable


To set max letters number for textarea, we do achieve that by writing:
<textarea maxLength="50"></textarea>

but, could I do something like below? Is there some way?

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

  selector: 'app-create-offer-page',
  template: `
    <textarea maxLength="textareaLength"></textarea>
export class CreateOfferPageComponent {
  textareaLength: number = 50;

I’m asking because that does not work.


You would need [] for Angular to interpret it as binding


This should work for native validation. Angular2 validators don’t currently support dynamic values.

Answered By – Günter Zöchbauer

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.