slevin
slevin

Reputation: 3886

textarea does not work in angular6

I am using angular 6 and I try to put a textarea in a form.

This is my code so far

<textarea rows="20" cols="50" id="mailtext" required [(ngModel)]="mailtext" name="mailtext" #mailtextvalidityMsg="ngModel" >Hi there</textarea>

I can see the text area in the html, but the "Hi there" text is not rendered. I dont get any errors in my console.

If I remove the [(ngModel)]="mailtext" name="mailtext" #mailtextvalidityMsg="ngModel" it works.

This is happening only for the textarea. For other fields in the same form, such as input type="email", there is no problem.

What am I missing?

Thanks

EDIT

I forgot to mention that I want to have line breaks and a link in the textarea, something like

Hi there , 

this is the code you have to use 

Click here

I want to have line breaks and the Click here must be a link

If I do

mailtext:any;
this.mailtext = 'Hi there,'+<br>+'this is the code you have to use';

I get Hi there,NaN

Thanks

Upvotes: 0

Views: 3349

Answers (1)

user184994
user184994

Reputation: 18281

It's probably being replaced the the ngModel binding at runtime.

If you want to have a default value, just set this.mailtext = 'Hi there' in the component

Upvotes: 1

Related Questions