Angular2 maxLength for textarea as variable

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

 [maxLength]="textareaLength"

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


Sure and it's pretty easy - just use attribute binding like so:

<textarea [attr.maxLength]="textareaLength"></textarea>

Expanding a little bit on the answer provided by @rinukkusu, you could even make the attribute optional by adding a ternary operator, like so:

<textarea [attr.maxLength]="textareaLength > 0 ? textareaLength : null"></textarea>

The null value removes the attribute completely from the element, which was something I needed.