错误TypeError:无法读取Object.eval

时间:2019-09-24 16:03:22

标签: java angular spring-boot browser ide

我的系统上正在运行angularspring boot。 路由到最后一页时,期望制定从上一条路由传递的值。但是我收到错误:

  

错误TypeError:无法读取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'); }

1 个答案:

答案 0 :(得分:0)

尝试使用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>

通知问号(?)在点运算符之前