Primeng风格的课程在使用组件时不起作用,仅在使用指令时工作
我正在使用Angular 12
和Primeng 13
开发Web应用程序。 但是,我面对一个奇怪的问题。考虑下面定义的两个简单按钮:
<p-button label="Delete" icon="pi pi-trash" class="mr-1 p-button-danger"></p-button>
<button pButton label="Delete" icon="pi pi-trash" class="mr-1 p-button-danger"></button>
根据Primeng文档,这两个按钮应以相同的方式行事。但是,对我而言,情况并非如此,以下是我的应用程序中的两个按钮渲染的方式:
基本上,当直接使用该组件(上面的代码示例中的第一个)似乎大多数样式类似乎不起作用。例如,在上面的p-button-danger
类中的示例中不应用适当的红色背景。我测试过的其他样式课程也是如此。相反,如果我使用pbutton
指令(样本中的第二个),一切都按预期工作。
我过去曾经使用过Primeng,而且我很确定我以前没有这个问题...知道为什么会发生这种情况吗?
I'm developing a web app using Angular 12
and PrimeNG 13
.
However, I'm faced with a weird issue. Consider the two simple buttons defined below:
<p-button label="Delete" icon="pi pi-trash" class="mr-1 p-button-danger"></p-button>
<button pButton label="Delete" icon="pi pi-trash" class="mr-1 p-button-danger"></button>
According to PrimeNG documentation, these two should behave the same way. However, this is not the case for me, here's how those two buttons render in my app:
Basically, when using the component directly (the first one in the code sample above) most style classes seem to not work. For example, in the sample above the p-button-danger
class does not apply the appropriate red background. Same goes with the other style classes I've tested. If instead I use the pButton
directive (second one in the sample) everything works as intended.
I've used PrimeNG in the past and I'm pretty sure I didn't have this problem before... any idea of why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为它们俩都无法完全一样。
对于
p-button
指令,您必须使用styleclass
属性,因为它不是直接应用于元素:cheers
this is because they both do not work exactly the same.
For the
p-button
directive, you must use thestyleClass
attribute, because it's not directly applied to the element :Cheers