【问题标题】:How to use isNaN and charAt in in Angular 7 typescript?如何在 Angular 7 打字稿中使用 isNaN 和 charAt?
【发布时间】:2018-12-06 05:21:00
【问题描述】:

我无法使用charAt(index)isNaN()。它说:

[ts] 找不到名称“isNaN”。

fuctiontocheckfirstchar(control: AbstractControl) {
  const val: string = control.value;

  if (!isNaN(val.charAt(0))) {
    return null;
  } else {
    return { 'pass': true };
  }
}

【问题讨论】:

  • 你试过 window.isNaN 了吗?
  • 试试 Number.isNaN()
  • 错字:fuction -> function

标签: javascript angular typescript angular7


【解决方案1】:

使用 Number.isNaN() 代替 isNaN()

anf for val.charAt() 确保

值 是字符串类型。

【讨论】:

  • 在代码中,OP 显示的val 被定义为const val: string,所以它应该是string,或者OP 还需要做些什么来确保val 的输入字符串?
猜你喜欢
  • 2019-12-24
  • 1970-01-01
  • 2019-07-25
  • 2018-04-15
  • 2015-03-04
  • 2019-01-19
  • 2019-04-06
  • 1970-01-01
  • 2016-12-10
相关资源
最近更新 更多