我的系统上运行着 Angular
和 spring 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/