I am using reactive forms and i seem to be having issues with what would seem random form fields. Any ideas as to why this is happening is apriciated.
I have just started using angular and material 7 if that helps
Interestingly enough adding and removing elements in the form causes issues with other elements.
ERROR Error: No value accessor for form control with unspecified name attribute
TS
export class VolunteerApplicationPersonalStepComponent implements OnInit
{
public readonly form: FormGroup;
constructor(private fb: FormBuilder) {
this.form = this.fb.group({
businessTelephoneExt: [''],
otherTelephone: [''],
otherTelephoneExt: [''],
});
}
}
HTML
<form [formGroup]="form">
<mat-form-field>
<input matInput i18n-placeholder placeholder="Business Extension"
[formControl]="form.get('businessTelephoneExt')">
</mat-form-field>
<app-telephone-input i18n-placeholder placeholder="Other Telephone"
[formControl]="form.get('otherTelephone')">
</app-telephone-input>
<mat-form-field>
<input matInput i18n-placeholder placeholder="Other Extension"
[formControl]="form.get('otherTelephoneExt')">
</mat-form-field>
<br>
<div class="group-margin group-min-width">
<button mat-stroked-button color="primary" matStepperPrevious i18n>Previous</button>
<button mat-raised-button color="primary" matStepperNext (click)="next()" i18n>Next</button>
</div>
</form>
as someone suggested .. formControlName="businessTelephoneExt"
App-Telephone Code (Note it used to have formControl NOT appFormControl)
export class TelephoneInputComponent implements OnInit {
@Input() public required = false;
@Input() public placeholder = '';
@Input() public appFormControl: NgControl;
constructor() {
}
public ngOnInit() {
}
}
<mat-form-field>
<input
matInput
type="tel"
[required]="required"
[placeholder]="placeholder"
[formControl]="appFormControl">
<mat-hint i18n>Please enter digits only</mat-hint>
<mat-error
*ngIf="appFormControl.hasError('phone')"
i18n>Invalid phone (requires 10 digits)
</mat-error>
</mat-form-field>
seems you cannot have a @Input() named formControl