Angular PrimeNG表单选择按钮禁用选项
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来制作响应式网站,非常方便。在这篇文章中,我们将知道如何在Angular PrimeNG中使用表格 选择按钮禁用选项。
SelectButton组件被用来制作一组按钮,用户可以从中选择一个值。可以利用optionDisabled属性来防止特定选项被选中。
Angular PrimeNG Form SelectButton Disabled 选项属性:
- option。它是一个数组,代表选择项,作为可用的选项显示。它是数组的数据类型,默认值为空。
- optionLabel。它用于给出一个选项的标签。它是字符串数据类型,默认值是标签。
- optionDisabled。它用于通过使用相应的名称来禁用该选项。它是字符串类型的,默认值是禁用。
创建Angular应用程序和模块安装:
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
- 要运行上述文件,请运行以下命令。
ng serve --save
例子1:这是一个基本的例子,展示了如何使用Angular PrimeNG Form SelectButton Disabled Options.。
- app.component.html
<h1 style="color: green">GeeksforGeeks</h1>
<h5>
Angular PrimeNG Form SelectButton
Disabled Options.
</h5>
<p-selectButton optionLabel="name"
optionDisabled="icon"
[options]="gfg">
</p-selectButton>
- app.component.ts
import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
gfg: any[];
constructor(
private primeNGConfig: PrimeNGConfig
) {
this.gfg = [
{ icon: 'pi pi-align-left' },
{ icon: 'pi pi-align-right' },
{ icon: 'pi pi-align-center' },
{ icon: 'pi pi-align-justify' },
];
}
}
- app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { SelectButtonModule }
from 'primeng/selectbutton';
import { ButtonModule } from 'primeng/button';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
SelectButtonModule,
ButtonModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
输出:

例子2:这是另一个基本例子,展示了如何使用**Angular PrimeNG Form SelectButton Disabled Options。
- app.component.html
<h1 style="color: green">GeeksforGeeks</h1>
<h5>
Angular PrimeNG Form SelectButton
Disabled Options
</h5>
<p-selectButton optionLabel="name"
optionDisabled="name"
[options]="gfg">
</p-selectButton>
- app.component.ts
import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
gfg: any[];
constructor(private primeNGConfig: PrimeNGConfig) {
this.gfg = [
{ name: 'Geek 1' },
{ name: 'Geek 2' },
{ name: 'Geek 3' },
];
}
}
- app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { SelectButtonModule }
from 'primeng/selectbutton';
import { ButtonModule } from 'primeng/button';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
SelectButtonModule,
ButtonModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
输出:

极客教程