首页 > 解决方案 > 表单组控件:无法读取未定义的属性“值”

问题描述

我有一个表单和equiid控件,我想检查equiid

if (this.formGroupContent.controls['equiid'].value===undefined){
  console.log("undefined value");
} else {
  console.log("has value");
}

但是当equiid为空时,在控制台中接收:

Cannot read property 'value' of undefined

标签: angular

解决方案


或许

this.formGroupContent.controls['equiid'] === undefined

它导致你提到的结果。

这只是我的一个想法,如有错误请指正。


推荐阅读