繁体   English   中英

错误类型错误:无法读取 Object.eval 处未定义的属性“testName”

[英]ERROR TypeError: Cannot read property 'testName' of undefined at Object.eval

我的系统上正在运行angularspring boot 当路由到最后一页时,预计会制定从先前路由传递的值。 但我收到错误:

错误类型错误:无法读取 Object.eval 处未定义的属性“pName”

其他团队成员在他们的系统上没有遇到这个问题。 我不确定是浏览器问题还是其他问题。

我尝试过的事情:

  • 清除浏览器缓存
  • 重新导入应用程序
  • 在另一个浏览器中尝试过

这是使用“pName”的代码。

 HTML1: <table class="row page-row align-items-start col-12"> <tr> <td>Name:</td> <td>{{projectBasicInfo['Address']['pName']}}</td> </tr> <tr> <td>Address:</td> <td>{{BasicInfo['Address']['pstreet']}}, {{BasicInfo['Address']['pcity']}}, {{BasicInfo['Address']['pstate']} {{BasicInfo['Address']['pzip']}}</td> </tr> <tr> <td>Term:</td> <td>{{BasicInfo['eDate']}} to {{BasicInfo['eDate']}}</td> </tr> </table> `````````````````````````````````````````````````````````````````````````````` HTML 2: <div class="list-group-item"> <h5>Name</h5> <p>{{quoteResult.pAddress.pName}}</p> </div> `````````````````````````````````````````````````````````````````````````````` HTML3: <div class="list-group-item"> <h6><b>Name</b></h6> <a>{{Result.pAddress.pName}}</a> </div> `````````````````````````````````````````````````````````````````````````````` HTML4: <div class="row page-row align-items-start"> <div class="col-6"> <input [ngClass]="{'is-invalid': pName.touched && pName.invalid}" class="form-control" formControlName="pName" type="text" maxlength="70"> <span *ngIf="pName.touched && pName.invalid" class="text-danger">This field is required</span> </div> </div> `````````````````````````````````````````````````````````````````````````````` Service: pAddress: this.fb.group({ pName: ['', Validators.required], pstreet: ['', Validators.required], pcity: ['', Validators.required], pstate: ['', [Validators.required, CustomValidators.StateRequirements]], pcounty: ['', Validators.required] }), `````````````````````````````````````````````````````````````````````````````` ts file: get pName(): AbstractControl { return this.pageData.formGroup.get('pAddress').get('pName'); }

尽量使用安全导航算子

<input [ngClass]="{'is-invalid': pName?.touched && pName?.invalid}" 
       class="form-control" formControlName="pName" 
       type="text"  maxlength="70">

<span *ngIf="pName?.touched && pName?.invalid" 
      class="text-danger">This field is required</span>

注意点运算符之前的问号 ( ? ) 符号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM