Skip to content

Mark FormControlDirective as standalone #56805

@bdorresteijn-visma

Description

@bdorresteijn-visma

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

It would be nice, if possible, to mark the FormControlDirective as a standalone component. That way it can be used as hostDirective in other components. For instance, we are using it (with workaround), to dynamically render and bind form-inputs.

Currently the following error is shown when the directive is used as host-directive.

[ERROR] TS-992014: Host directive FormControlDirective must be standalone [plugin angular-compiler]

image

With the following piece of code

hostDirectives: [ {
  directive: FormControlDirective,
  inputs: [ 'formControl' ]
} ]

Proposed solution

Mark FormControlDirective as standalone

Alternatives considered

Currently we extend the FormControlDirective, so it can be marked to as standalone without any other changes. That custom component we can than use as HostDirective.

import { Directive } from '@angular/core';
import { FormControlDirective } from '@angular/forms';

@Directive( {
  standalone: true
} )
export class HostFormControlDirective extends FormControlDirective {
}

stackblitz example

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions