gpt4 book ai didi

Angular 编译错误 : NG6001: The class is listed in the declarations of the NgModule 'AppModule' , 但不是指令、组件或管道

转载 作者:行者123 更新时间:2023-12-03 07:34:33 25 4
gpt4 key购买 nike

应用程序无法编译并出现错误

error NG6001: The class 'NavigationMenuItemComponent' is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.



当我删除带有参数的构造函数时,错误消失了。
如何在维护具有参数的构造函数的同时解决此问题,因为我想用来初始化组件列表,而不必为列表中的每个成员调用 set 方法


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 {}
}

最佳答案

你必须运行 npm install创建新组件时。热重载似乎无法添加组件。

关于Angular 编译错误 : NG6001: The class is listed in the declarations of the NgModule 'AppModule' , 但不是指令、组件或管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61308517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com