应用无法编译并出现错误
当我删除带有参数的构造函数时,错误消失了。
我如何在维护具有参数的构造函数的同时解决此问题,因为我想用来初始化组件列表,而不必为列表中的每个成员调用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 - Angular编译错误:NG6001:该类在NgModule的声明中列出 'AppModule',但不是指令,组件或管道,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61308517/