从textarea获取用户输入 [英] Get user input from textarea

查看:119
本文介绍了从textarea获取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是angular2的新手.我想将来自文本区域的用户输入存储在组件中的变量中,以便可以将一些逻辑应用于此输入.我尝试了ngModel,但是它不起作用.我的文本区域代码:

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>

在我的组件内部:

str: string;
//some logic on str

但是在组件内部的str中没有任何值.我使用ngModule的方式是否有错误?

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

推荐答案

<pre>
  <input type="text"  #titleInput>
  <button type="submit" (click) = 'addTodo(titleInput.value)'>Add</button>
</pre>

{
  addTodo(title:string) {
    console.log(title);
  }
}    

这篇关于从textarea获取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆