Angular 10: Class is using Angular features but is not decorated

See original GitHub issue

I am trying to use this library with Angular 10. I get the following error when I try to build the Angular project:

src/directives/generated/value-accessor.ts:4:14 - error NG2007: Class is using Angular features but is not decorated. Please add an explicit Angular decorator.

4 export class ValueAccessor implements ControlValueAccessor {

This new behaviour seems to have been introduced by https://github.com/angular/angular/pull/36921.

Manually appending @Directive() to ValueAccessor fixes the issue:

import {Directive, ElementRef, HostListener} from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';

@Directive()
export class ValueAccessor implements ControlValueAccessor {
// ...

I wanted to create a pull request for that, but @Directive changed between Angular 9 and Angular 10. In Angular 9, @Directive() requires a selector attribute, while in Angular 10, you can pass it without any option.

So maybe Stencil needs to be aware of the Angular version effectively used?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

14reactions
avchugaevcommented, Jan 16, 2021

For me it occurs on an abstract class.

Same story…

Angular team, please let us write normal abstract/base classes. This limitation looks ridiculous. It forces me to decorate my abstract class just because it implements OnDestroy interface.

And even more, compiler emits this error only in normal mode. When I run the prod build, everything’s fine.

@Injectable() // 👈 I have to add this for no real reason to satisfy the compiler. why?!
export abstract class LocalStore<TState> extends StoreBase<TState> implements OnDestroy {
  ngOnDestroy(): void {
    this.complete();
  }
}
8reactions
Hamckercommented, Oct 27, 2020

For me it occurs on an abstract class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class is using Angular features but is not decorated. Please ...
From Angular 10, you can fix this issue by adding the decorator @Injectable() to your abstract base class like ...
Read more >
Missing @Directive()/@Component() decorator migration
This migration adds an empty @Directive() decorator to undecorated base classes that: Use Angular features; Are extended by directives or components.
Read more >
Answer: Class is using Angular features but is not decorated ...
You'll need to add a @Component decorator to that base class (which should probably also be declared abstract ).
Read more >
class is using angular features but is not ... - Code Grepper
1. After angular 10, all the class with service function needs to inject: ; 2. @Injectable() //reason to satisfy the compiler.
Read more >
Class is using Angular features but is not decorated ... - iTecNote
You'll need to add a @Component decorator to that base class (which should probably also be declared abstract ). ... For Angular 10+,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found