PrimeNG Accordion 无法正常工作和显示

问题描述 投票:0回答:3

我尝试根据官方文档

使用primeNG Accordion

这是我的代码:

<p-accordion [multiple]="true">
    <p-accordionTab header="Godfather I">
        The story begins  as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
    </p-accordionTab>
    <p-accordionTab header="Godfather II">
        Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows.
   </p-accordionTab>
    <p-accordionTab header="Godfather III">
        After a break of more than  15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
    </p-accordionTab>
</p-accordion>

我确保

import { AccordionModule } from 'primeng/accordion'
和 import
AccordionModule
位于 app.module.ts

问题#1:我遇到了一个错误:

ERROR Error: "Found the synthetic listener @tabContent.done. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application."

我真的需要包含

BrowserAnimationsModule
NoopAnimationsModule
吗?官方文档中没有提到

问题#2:我添加了

NoopAnimationsModule
,现在问题消失了,但显示效果很糟糕。

手风琴内容和标题似乎重叠:

有一个选项卡处于活动状态:

请帮忙。如果有任何误用,请随时纠正我。 预先感谢您!

css angular angular6 primeng
3个回答
2
投票

感谢评论部分的 David 和 Daniel。

对于问题 #1:是的,我需要导入

BrowserAnimationsModule

对于问题 #2:缺少

primeng.min.css
。我必须在 angular.json 中添加“/node_modules/primeng/resources/primeng.min.css”


1
投票

内容未隐藏的问题是因为您的页面中没有包含

primeng.css
,PrimeNG 组件会自动将一组固定的 css 类应用于其组件,在您的情况下,这是负责的以下类隐藏手风琴面板的内容:

.ui-accordion-content-wrapper-overflown {
    overflow: hidden;
}

0
投票

我知道这是一个老问题,但是对于任何到达这里想知道为什么在检查了所有可能的内容后该组件仍然无法工作的人来说,答案在于导入。我在 AppModule 中导入了 BrowserAnimationsModule 和 NoopAnimationsModule。导入的顺序很重要。您需要在 BrowserAnimationsModule 之前导入 NoopAnimationsModule。

如果您完全删除 NoopAnimationsModule 导入,它也会起作用,但就我而言,我将其留在那里,因为我还不知道它是否在项目中的其他任何地方使用。

  • PrimeNG:17.3.2
  • 角度:17.0.8
  • 角度动画:17.0.8
© www.soinside.com 2019 - 2024. All rights reserved.