1

我是primeng的新手,遇到了这个困难。当我将 ap-menuitem放入 ap-menubar时,角度会给我以下错误:

'p-menuitem' is not a known element:
1. If 'p-menuitem' is an Angular component, then verify that it is part of this module.
2. If 'p-menuitem' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

现在我明白我需要在 app.module.ts 中添加模块,我做了:

app.module.ts 代码

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {MenubarModule} from 'primeng/menubar';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    MenubarModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

HTML 代码:

<p-menubar [model]="items">
   <p-menuitem>Any code here</p-menuitem>
</p-menubar>

我还将它导入MenubarModule到与 HTML 相同的 component.ts 中,导入行虽然在那里褪色。我在这里缺少什么吗?

版本:

"@angular/common": "~12.0.3"
"@angular/compiler": "~12.0.3"
"@angular/core": "~12.0.3"

"primeng": "12.0.0"
"primeicons": "4.1.0"
4

2 回答 2

1

在 Visual Studio Code 中使用Angular Language Service扩展时,请确保将“查看引擎”选项与您的 Angular 版本相匹配。

这可以在“扩展”视图中完成,然后单击该Angular Language Server项目,然后在齿轮图标(“管理”按钮)上选择“扩展设置”。

例如,在使用 Angular v12 时,不要选中“使用旧版视图引擎语言服务”选项,因为较新版本的 Angular 将 Ivy 作为其主要视图引擎。对于旧版本,您应该选中此选项以使语言服务器扩展正常工作。

请注意,可能同时存在多个重叠配置,例如“用户”+“工作区”。尤其是在处理远程开发容器时,扩展似乎很难读取设置——例如,在我的情况下,“远程 [开发容器]”选项卡中的特定设置似乎已被完全忽略,所以我不得不覆盖我的“用户”设置带有不需要的设置,以使警告消失。

于 2021-10-12T21:09:49.967 回答
0

我终于在这里找到了解决方案-> https://github.com/primefaces/primeng/blob/master/src/app/showcase/components/menubar/menubardemo.module.ts

您必须在您的 component.module.ts 中导入 MenubarModule 并在 @NgModule -> 导入中声明它

import { MenubarModule } from 'primeng/menubar';
@NgModule({
  imports: [
    CommonModule,
    AppRoutingModule,
    MenubarModule
  ],
于 2021-12-01T16:00:52.737 回答