Angular 10 Upgrade: Why use @Directive() instead of @Component() for abstract (component) classes?

Viewed 2831

I recently upgraded my Angular app from v9 to v10.

I noticed that undecorated classes are not supported anymore. See here

So during ng upgrade my abstract components without decorates have been changed to have a @Directive() decoratror.

For example

export abstract class AbstractFormControl implements ControlValueAccessor { ... }

was changed into

@Directive()
export abstract class AbstractFormControl implements ControlValueAccessor { ... }

Why does Angular use @Directive. Wouldn't @Component be a better way because the class is rather a Component than a Directive? What was the intention?

1 Answers

Component requires you to specify template or templateUrl, which cannot be used with an abstract class.

As mentioned in the comments - Component is a special type of Directive. So it is okay to inherit from an abstract Directive.

Related