I recently upgraded my project from Angular 9 to Angular 10, and now adding a decorator to classes is mandatory. I have a model class that has no decorator . It's also a TypeScript file.
Let's say I have the following model
export class Car {
model: string;
type: string;
year: string;
}
Now when I run ng serve
, it throws that the class has a missing decorator. It's not a component, nor a directive.
Specific error is the following:
NG2007: Class is using Angular features but is not decorated. Please add an explicit Angular decorator.
12 export class Car {
~~~~~~~
It even complains about classes that I use later on to be extended in some of my components. Forces me to use decorator every time.
How can I handle this issue?
According to the official docs, there's a way to handle these situations with base classes and stuff, is to add an empty Directive() decorator.
Here's the reference .
I made it work this way, and no complaints during ng serve now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.