加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在角度2中检查文本区域是否为空?

发布时间:2020-12-17 06:51:41 所属栏目:安全 来源:网络整理
导读:我有文本区域框,我需要在文本区域输入文本时检查数据.我写的更改方法但是没有工作 这是代码. textarea (change)="textAreaEmpty(textValue)" #textValue/textarea 零件 textAreaEmpty(text:string){ if(text.length 0) console.log(text); } 我还需要检查用
我有文本区域框,我需要在文本区域输入文本时检查数据.我写的更改方法但是没有工作
这是代码.

<textarea (change)="textAreaEmpty(textValue)" #textValue></textarea>

零件

textAreaEmpty(text:string){
      if(text.length > 0)
        console.log(text);
  }

我还需要检查用户在文本区域中输入了多少行.我在anuglar2中找到任何解决方案,我能够使用jquery或javascript获取数据,但我不想使用它.我想在角度2使用它,任何身体可以帮助我吗?

解决方法

I am able to get the data with jquery or javascript,but i don’t want to use that. i want to use it in angular 2,Can any body help me?

使用[ngModel]如果你想做更多“Angularish”……

<textarea [(ngModel)]="textValue" (ngModelChange)="textAreaEmpty()"></textarea>

TS:

textValue: string = '';

textAreaEmpty(){
  if (this.textValue != '') {
    console.log(this.textValue);
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读