Primeng风格的课程在使用组件时不起作用,仅在使用指令时工作

发布于 2025-02-12 21:08:18 字数 829 浏览 1 评论 0原文

我正在使用Angular 12Primeng 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨光如昨 2025-02-19 21:08:18

这是因为它们俩都无法完全一样。
对于p-button指令,您必须使用styleclass属性,因为它不是直接应用于元素:

<p-button styleClass="p-button-sm p-button-raised mr-2" label="Something" icon="pi pi-upload">
</p-button>

cheers

this is because they both do not work exactly the same.
For the p-button directive, you must use the styleClass attribute, because it's not directly applied to the element :

<p-button styleClass="p-button-sm p-button-raised mr-2" label="Something" icon="pi pi-upload">
</p-button>

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文