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

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

问题描述

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

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

在我的组件内部:

str:字符串;//str上的一些逻辑

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

解决方案

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

{addTodo(标题:字符串){控制台日志(标题);}}

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 ?

解决方案

<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天全站免登陆