I have an API which for example returns the following model:
public class TestModel
{
int Id { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string DisplayName { get; set; }
}
I have an Angular Reactive form with the following FormGroup:
myForm = new FormGroup({
id: new FormControl(),
userName: new FormControl(),
firstName: new FormControl(),
surname: new FormControl()
});
When I load the data into my form I receive the following error: Cannot find form control with name: displayName.
I know the control isn't in my form group but I don't want it there as I would never change that value on the form. Is there a way round this or do I need to add it to the form group.
The form control isn't part of the HTML.It is not referenced anywhere on the Angular side and that is what I want.
<input type="text" [formControl]="myForm.get('userName')"/>
<input type="text" [formControl]="myForm.get('firstName')"/>
<input type="text" [formControl]="myForm.get('surname')"/>
Thanks