You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PrimeNG组件类中修改按钮标签(不使用HTML的label属性)

Solution for Setting PrimeNG Button Label from Component Class

To set your PrimeNG button's label to "delivery address" from the component class (instead of using the label attribute directly in HTML), follow these simple steps:

Step 1: Define the Label Variable in Your Component Class

In your Angular component's TypeScript file, declare a public property to hold the button label text:

import { Component } from '@angular/core';

@Component({
  selector: 'app-your-component', // Replace with your component's actual selector
  templateUrl: './your-component.component.html'
})
export class YourComponentComponent {
  // Store the label text in a class property
  buttonLabel: string = "delivery address";
}

Step 2: Bind the Variable to Your PrimeNG Button

Connect the class variable to your button in the template using one of these two reliable methods:

PrimeNG's pButton component has a built-in label input that you can bind to your class variable via property binding:

<button pButton type="button" [label]="buttonLabel"></button>

Option 2: Use Angular Interpolation with Content Projection

You can also insert the variable directly inside the button tag using Angular's interpolation syntax:

<button pButton type="button">{{ buttonLabel }}</button>

Both approaches will render the button with the "delivery address" label pulled from your component class, keeping your template clean and separating text content from markup.

内容的提问来源于stack exchange,提问作者Thejashwini Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:24:00