My app is having trouble compiling and showing the error
Error NG6001: The class
NavigationMenuItemComponent
is included in the declarations of the NgModuleAppModule
, but it is not a directive, component, or pipe. You must either remove it from the NgModule's declarations or add an appropriate Angular decorator.
I noticed that the error disappears when I remove the constructor with parameters. However, I would like to keep the constructor with parameters because I want to use it to initialize a list of components without having to call set methods for each member in the list. How can I resolve this issue?
import {
Component,
OnInit
} from '@angular/core';
@Component({
selector: 'app-navigation-menu-item',
templateUrl: './navigation-menu-item.component.html',
styleUrls: ['./navigation-menu-item.component.scss']
})
export class NavigationMenuItemComponent implements OnInit {
static readonly ID_PREFIX: string = 'sidebar-menuitem-';
static readonly ICON_CLASS_PREFIX: string = 'mdi mdi-';
constructor(id: string, iconClass: string) {
this._id = NavigationMenuItemComponent.ID_PREFIX + id;
this._iconClass = NavigationMenuItemComponent.ICON_CLASS_PREFIX + iconClass;
}
//constructor() {}
private _id: string;
private _iconClass: string;
get id() {
return this._id;
}
get iconClass() {
return this._iconClass;
}
set id(id: string) {
this._id = NavigationMenuItemComponent.ID_PREFIX + id;
}
set iconClass(iconClass) {
this._iconClass = NavigationMenuItemComponent.ID_PREFIX + iconClass;
}
ngOnInit(): void {}
}