如何将文本添加到PrimeNG速拨选项按钮中?

huangapple go评论63阅读模式
英文:

How to add text into PrimeNG speeddial option buttons?

问题

我想在我的快速拨号组件选项中打印文本而不是图标。

我想要这样。

提前感谢。

英文:

I want to print a text instead of icons in the options of my sppeddial component.

如何将文本添加到PrimeNG速拨选项按钮中?

I want this.

如何将文本添加到PrimeNG速拨选项按钮中?

Thanks in advance

答案1

得分: 2

要实现这一点,您可以按照以下步骤进行:

  1. 在组件的 TypeScript 文件 (component.ts) 中定义您的模型列表:
this.items = [
  {
    icon: 'one',
    command: () => {
      this.messageService.add({
        severity: 'info',
        summary: 'Add',
        detail: 'Data Added',
      });
    },
  },
  {
    icon: 'two',
    command: () => {
      this.messageService.add({
        severity: 'success',
        summary: 'Update',
        detail: 'Data Updated',
      });
    },
  },
  {
    icon: 'pi pi-trash',
    command: () => {
      this.messageService.add({
        severity: 'error',
        summary: 'Delete',
        detail: 'Data Deleted',
      });
    },
  },
  {
    icon: 'pi pi-upload',
  },
  {
    icon: 'pi pi-external-link',
    url: 'http://angular.io',
  },
];

随意更改图标属性的名称,因为它将在底层创建与图标名称对应的类的 span 元素。这个类将被用作选择器来指定您的项。

  1. 在组件的 HTML 文件 (component.html) 中使用 p-speedDial 组件:
<p-speedDial [model]="items" direction="up"></p-speedDial>
  1. 在组件的 SCSS 文件 (component.scss) 中,选择 spans 并更改其内容:
:host ::ng-deep .p-speeddial-action-icon.one::before {
  content: '1' !important;
}

:host ::ng-deep .p-speeddial-action-icon.two::before {
  content: '2' !important;
}

这些样式将把前两个按钮的图标内容分别更改为 '1' 和 '2'。

英文:

To achieve this, you can follow these steps:

  1. Define your model list in the component's TypeScript file (component.ts):
this.items = [
  {
    icon: &#39;one&#39;,
    command: () =&gt; {
      this.messageService.add({
        severity: &#39;info&#39;,
        summary: &#39;Add&#39;,
        detail: &#39;Data Added&#39;,
      });
    },
  },
  {
    icon: &#39;two&#39;,
    command: () =&gt; {
      this.messageService.add({
        severity: &#39;success&#39;,
        summary: &#39;Update&#39;,
        detail: &#39;Data Updated&#39;,
      });
    },
  },
  {
    icon: &#39;pi pi-trash&#39;,
    command: () =&gt; {
      this.messageService.add({
        severity: &#39;error&#39;,
        summary: &#39;Delete&#39;,
        detail: &#39;Data Deleted&#39;,
      });
    },
  },
  {
    icon: &#39;pi pi-upload&#39;,
  },
  {
    icon: &#39;pi pi-external-link&#39;,
    url: &#39;http://angular.io&#39;,
  },
];

Feel free to change the icon property to any name you desire, as it will create a span element with a class corresponding to the icon name under the hood. This class will be used as a selector to specify your item.

  1. Use the p-speedDial component in your component's HTML file (component.html):
&lt;p-speedDial [model]=&quot;items&quot; direction=&quot;up&quot;&gt;&lt;/p-speedDial&gt;
  1. In the component's SCSS file (component.scss), select the spans and change their content:
:host ::ng-deep .p-speeddial-action-icon.one::before {
  content: &#39;1&#39; !important;
}

:host ::ng-deep .p-speeddial-action-icon.two::before {
  content: &#39;2&#39; !important;
}

These styles will change the icon content of the first two buttons to '1' and '2' respectively.

> it's a workaround but it works

huangapple
  • 本文由 发表于 2023年6月22日 08:01:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定