Injecting FormControlDirective says it can't find unspecified name

177 Views Asked by At

I'm injecting FormControlDirective in my CVA like so:

@Component({
    selector: 'app-boolean-select',
    standalone: true,
    imports: [ReactiveFormsModule],
    template: '<input [formControl]="formControl"/>',
})
export class BooleanSelectWithTooltipComponent implements ControlValueAccessor, OnInit {
    readonly #directive = inject(FormControlDirective, {self: true})
    protected readonly formControl = this.#directive.control as FormControl<boolean | null>

    ngOnInit(): void {
        this.#directive.valueAccessor = this
    }

Since I'm getting the containing control, I can't use the providers array and thus I'm assigning the valueAccessor directly. However, that results in a slew of errors in the console saying both of these:

NG01203: No value accessor for form control unspecified name attribute. Find more at https://angular.io/errors/NG01203

Cannot find control with unspecified name attribute

0

There are 0 best solutions below