3

I would like to get rid of the Error above. It started to appear after re-installed dependencies using npm i.

I tried removing "implements onInit" and it disappeared So the problem is related to it. But I want to use "implements onInit" without getting this error. I suspect it has to do also with typescript version (Which i upgraded to the latest).

Update: Of course I implemented ngOnInit function inside the class.

Error Message:

Class is using Angular features but is not decorated. Please add an explicit Angular decorator.(-992007)?

Code:

export class SomeClass implements OnInit {
ngOnInit():void{ 
//some code};
}
Uri Gross
  • 484
  • 1
  • 8
  • 20
  • 1
    Just revert the Typescript version to what it was maybe? – MikeOne Aug 30 '22 at 19:46
  • when u have implements onInit u must have ngOnInit function declared within class or it will error – danday74 Aug 30 '22 at 20:27
  • I edited my question. I have ngOnInit() inside the class I just forgot to mention it. I want to use the latest ts version otherwise what's the point to be with lower version instead of fizong the problem? – Uri Gross Aug 30 '22 at 20:41

2 Answers2

2

This error happened after updating typescript to latest. What I did is to rollback command

npm i typescript@4.7.2

And it was fixed.

Uri Gross
  • 484
  • 1
  • 8
  • 20
0

From angular 13 you will be getting this error I guess, if you are using angular features you need a decorator for it, you can simply add a dummy decorator for this and solve your issue!

@Directive()
export class TestClass {

}

implements just enforces that ngOnInit needs to be present inside the class, there is no use for it outside of an angular component!

Naren Murali
  • 19,250
  • 3
  • 27
  • 54
  • Adding @Directive didn't work for me. But I removed the "Implements" .. as a second thought I really don't see in this type of component a point to do so. Thank you for helping – Uri Gross Aug 30 '22 at 20:46
  • @UriGross You can also change the class to abstract class maybe that is an alternative, anyway good that its fixed! – Naren Murali Aug 30 '22 at 20:47