Я могу связать другие значения, кроме 3 значений поля ввода в той же форме группы. Он показывает строку ошибки для строк HTML, где я добавил сообщение об ошибке через функцию get от ts.
TS :
get detailsInfo() {
return this.agentbasicInfoForm.controls;
}
this.agentbasicInfoForm = this.FB.group({
groupCode: this.agentDetailsList.basicInfo.groupAgent,
agentCode: [this.agentDetailsList.basicInfo.agentCode, Validators.required],
agencyType: [this.agentDetailsList.basicInfo.agentType, Validators.required],
})
HTML:
<select class="custom-select" formControlName="agencyType" name="agencyType"
[ngClass]="{ 'is-invalid': submitted && detailsInfo.agencyType.errors }"
(change)="SelectedAgentType($event.target.value)">
<option value=''>Select Agent Type </option>
<option *ngFor="let agencyType of detailsSelectDropDown?.AgentType" [value]='agencyType.id'>
{{agencyType.value}}
</option>
</select>
<div *ngIf="submitted && detailsInfo.agencyType.errors" class="invalid-feedback">
<div *ngIf="detailsInfo.agencyType.errors.required">Agency Type is required</div>
</div>
TS:
getAllDetails() {
let params = {
GroupAgent: this.groupCode,
agentCode: this.agentCode
}
this.agentViewDetailsService.getDetailsTabAllData(params).subscribe((res) => {
this.agentDetailsList = res.result;
this.initAllForms()
console.log(this.agentDetailsList,"all details");
})
}
DEMO
![enter image description here](https://i.stack.imgur.com/GvZQH.png)