离开textarea在删除时给出一个非空而非空字符串

问题描述 投票:1回答:1

在我的Ionic 3项目中,我正在检查写在ion-textarea上的字符串是否为空。 如果我没有在该区域写任何东西,它会正确地告诉我它是null,但是如果我写了一些然后删除它,它就不会将它识别为null或空,但如果我尝试打印当然的值它打印一个空字符串。 这是一个问题,因为它绕过输入的所有检查我仍然是空的。 这是我正在使用的代码,在html中:

 <ion-textarea [(ngModel)]="duration"  placeholder="Duration"></ion-textarea>

并在.ts文件中:

 if (this.duration==null || this.duration==''){ 
      console.log("Duration is empty")
    } else {
 console.log("Duration not empty")
}
javascript textarea ionic3
1个回答
0
投票

你把它放在.ts文件中吗? duration: string = '';

© www.soinside.com 2019 - 2024. All rights reserved.