【发布时间】:2021-06-09 12:53:11
【问题描述】:
我是primeng的新手,遇到了这个困难。当我将p-menuitem 放入p-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"
【问题讨论】:
-
根据他们的docs,似乎没有
p-menuitem指令。你试过这个<p-menubar [model]="items"></p-menubar>吗?你能告诉我们items属性的内容吗? -
@DavidFontes
<p-menubar [model]="items"></p-menubar>按照您提供的链接中显示的方式工作。这是相同的代码 -
是的,我从他们的文档中复制,但我很困惑,这不符合您的需求吗?如果没有,您到底想达到什么目的?自定义样式?自定义内容?
-
我不确定
p-menuitem是像p-menubar这样的指令还是像<label class="p-menuitem"></label>那样的预定义类 -
根据他们的文档,它是一个用于样式目的的 css 类。
标签: angular primeng menubar angular12