我有一个类结构,看起来像下面的JDL
entity Address {
address String required,
city String required,
postalCode String required,
country String required,
}
entity MainEntity {
<some fields>
}
relationship OneToOne {
MainEntity {addressFirst} to Address,
MainEntity {addressSecond} to Address
}
我使用JHipster
生成了所有文件。
在视图级别,我尝试在一个视图中插入MainEntity
的所有详细信息。
<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">
<div class="form-group">
<label class="form-control-label" jhiTranslate="mainEntity.addressFirst.address" for="field_addressFirst_address">Address</label>
<input type="text" class="form-control" name="address" id="field_addressFirst_address"
[(ngModel)]="mainEntity.addressFirst.address" required maxlength="240"/>
<div [hidden]="!(editForm.controls.address?.dirty && editForm.controls.address?.invalid)">
<small class="form-text text-danger"
[hidden]="!editForm.controls.address?.errors?.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
[hidden]="!editForm.controls.address?.errors?.maxlength" jhiTranslate="entity.validation.maxlength" translateValues="{ max: 240 }">
This field cannot be longer than 240 characters.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" jhiTranslate="mainEntity.addressSecond.address" for="field_addressSecond_address">Address</label>
<input type="text" class="form-control" name="address" id="field_addressSecond_address"
[(ngModel)]="mainEntity.addressSecond.address" required maxlength="240"/>
<div [hidden]="!(editForm.controls.address?.dirty && editForm.controls.address?.invalid)">
<small class="form-text text-danger"
[hidden]="!editForm.controls.address?.errors?.required" jhiTranslate="entity.validation.required">
This field is required.
</small>
<small class="form-text text-danger"
[hidden]="!editForm.controls.address?.errors?.maxlength" jhiTranslate="entity.validation.maxlength" translateValues="{ max: 240 }">
This field cannot be longer than 240 characters.
</small>
</div>
</div>
</form>
我很困惑如何更新editForm.controls.address
字段以分隔这两个字段的验证。
我尝试使用editForm.controls.addressSecond.address
并收到错误消息,其中addressSecond
为undefined
。
我甚至无法在打字稿文件中找到editForm
或controls
的任何声明。任何帮助表示赞赏。