Get user input from textarea
<pre> <input type="text" #titleInput> <button type="submit" (click) = 'addTodo(titleInput.value)'>Add</button></pre>{ addTodo(title:string) { console.log(title); }}
I think you should not use spaces between the [(ngModel)]
the =
and the str
. Then you should use a button or something like this with a click function and in this function you can use the values of your inputfields
.
<input id="str" [(ngModel)]="str"/><button (click)="sendValues()">Send</button>
and in your component file
str: string;sendValues(): void {//do sth with the str e.g. console.log(this.str);}
Hope I can help you.
Tested with Angular2 RC2
I tried a code-snippet similar to yours and it works for me ;)see [(ngModel)] = "str" in my templateIf you push the button, the console logs the current content of the textarea-field. Hope it helps
textarea-component.ts
import {Component} from '@angular/core';@Component({ selector: 'textarea-comp', template: ` <textarea cols="30" rows="4" [(ngModel)] = "str"></textarea> <p><button (click)="pushMe()">pushMeToLog</button></p> `}) export class TextAreaComponent { str: string; pushMe() { console.log( "TextAreaComponent::str: " + this.str); }}