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
?
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.
<textarea> does not support the value attribute.
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.
The value property sets or returns the contents of a text area.
<pre> <input type="text" #titleInput> <button type="submit" (click) = 'addTodo(titleInput.value)'>Add</button> </pre> { addTodo(title:string) { console.log(title); } }
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