Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user input from textarea

I'm new to angular2. I want to store user input from a text area in a variable in my component so I can apply some logic to this input. I tried ngModel but it doesn't work. My code for the textarea:

<textarea cols="30" rows="4" [(ngModel)] = "str"></textarea> 

And inside my component:

str: string; //some logic on str 

But I don't get any value in str inside my component. Is there an error with the way I'm using ngModule ?

like image 223
Maryam Avatar asked Jun 18 '16 14:06

Maryam


People also ask

How do I get input from text area?

Use the value property to get the value of a textarea, e.g. const value = textarea. value . The value property can be used to read and set the value of a textarea element. If the textarea is empty, an empty string is returned.

Does textarea have value attribute?

<textarea> does not support the value attribute.

How do I display textarea content in HTML?

Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.

What property would you use to get the text that has been entered into a textarea?

The value property sets or returns the contents of a text area.


1 Answers

<pre>   <input type="text"  #titleInput>   <button type="submit" (click) = 'addTodo(titleInput.value)'>Add</button> </pre>  {   addTodo(title:string) {     console.log(title);   } }     
like image 190
Arthur Qocharyan Avatar answered Oct 09 '22 08:10

Arthur Qocharyan