How do I wrap text and have support for multiple line, using angular material 2 and angular.
<md-input-container fxFlex="18" fxFlexOffset="1">
<textarea [(ngModel)]="Comments" name="Comments" mdInput placeholder="Comments" ></textarea>
<md-error>This field is required</md-error>
</md-input-container>
Wrapping text mean, text should be appear multi line if content is longer than width.
To wrap text in an Input Text Field, select 'textarea' in the properties palette. To wrap text in a regular text field, change it to multi line.
To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.
Matinput is an Angular directive that primarily allows input and text area elements to work with a form field. With this, you can display placeholders perfectly, add custom error messages, a clear button, specify the maximum length of the text or add prefixes and suffixes for a seamless user experience.
MatFormFieldControl. An interface which allows a control to work inside of a MatFormField .
Doesn't textarea
elements have multi-line support? Did you mean setting the rows for the textarea
? Just use the native rows
attribute and set it to the value (as a number) of your choice.
<md-input-container fxFlex="18" fxFlexOffset="1">
<textarea [(ngModel)]="Comments" name="Comments" mdInput placeholder="Comments" rows="3"></textarea>
<md-error>This field is required</md-error>
</md-input-container>
As for wrapping the text, I don't really understand what you mean. Could you please elaborate on that?
Not the exact answer for the question but since this is the best match in google search,
to set rows for a textarea in angular apperantly we need to usecdkTextareaAutosize, cdkAutosizeMinRows
attributes .
<mat-form-field>
<textarea matInput placeholder="Your Message" formControlName="message" cdkTextareaAutosize
cdkAutosizeMinRows="6"></textarea>
</mat-form-field>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With