java - 错误类型错误 : Cannot read property 'testName' of undefined at Object. eval

标签 java angular spring-boot browser ide

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

ERROR TypeError: Cannot read property 'pName' of undefined at Object.eval

其他团队成员的系统上没有遇到此问题。不知道是浏览器问题还是其他问题。

我尝试过的事情:

  • 已清除浏览器缓存
  • 重新导入应用程序
  • 在其他浏览器中尝试过

这是使用“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'); }

最佳答案

尝试使用safe navigational operator

<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>

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

关于java - 错误类型错误 : Cannot read property 'testName' of undefined at Object. eval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58084235/

相关文章:

java - 获取 PDF 文件特定行之后的行

java - 结果集耗尽 Oracle 查询

angular - RxJs Observable 未调用完整方法

java - 在区域设置 'pl_PL' 的代码下未找到消息

java - 通过带有 Spring 数据的日期进行对象恢复

java - 我需要帮助将图像存储在内部目录中,并且其路径已插入SQLite中

java - 无需用户输入密码即可以编程方式配对蓝牙设备

angular - Ionic2 StorageModule/更新列表

javascript - 如何访问 Angular 4 服务中的 DOM 元素?

spring - 此应用程序没有明确的/错误映射,因此您将其视为后备。 - Spring 启动 - JSP