In my project using Angular 6 and reactive forms, I have a grid with a Detail
button that opens a modal window displaying student information. However, when implementing the HTML for the dialog box as shown below, I encountered an error message stating:
No value accessor for form control with name: studentNumber
. Is there an issue with my HTML logic?
The current implementation does not seem to be functioning correctly.
<form [formGroup]="studentForm">
<p-dialog header="Student Detail" [(visible)]="displayStudentForm">
<div class="p-grid">
<label>Student Number</label>
<label formControlName="studentNumber"></label>
</div>
<div class="p-grid">
<label>Student Age</label>
<label formControlName="studentAge"></label>
</div>
<div class="p-grid">
<label>Student Type</label>
<label formControlName="studentType"></label>
</div>
</p-dialog>
</form>
Although the following code works perfectly, it is quite lengthy to write repeatedly throughout the application.
<label>{{studentForm.controls.studentNumber.value}}</label>
This simpler implementation also works perfectly:
<input formControlName="studentNumber">