Open In App

Angular PrimeNG TriCheckbox Component

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the TriCheckbox component in Angular PrimeNG.

TriCheckbox component: It allows a user to make a checkbox with three states ie, true, false & null conditions.



Properties:

Event:



 

Styling:

Creating Angular application & module installation:

Project Structure: It will look like the following:

 

Example 1: This is the basic example that shows how to use the TriCheckbox component. 




<h2>GeeksforGeeks</h2>
<h5>PrimeNG TriCheckbox component</h5>
<p-triStateCheckbox label="Enabled Checkbox"></p-triStateCheckbox>
  
<p-triStateCheckbox
  disabled="true"
  label="Disabled Checkbox">
</p-triStateCheckbox>




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 { TriStateCheckboxModule } 
    from "primeng/tristatecheckbox";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    TriStateCheckboxModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Example 2: In this example, we will know how to use readonly and style property in the triCheckbox component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG TriCheckbox component</h5>
<p-triStateCheckbox label="Enabled Checkbox"></p-triStateCheckbox>
  
<p-triStateCheckbox
  readonly="true"
  label="Readonly Checkbox">
</p-triStateCheckbox>
  
<p-triStateCheckbox
  readonly="true"
  style="border: 5px dotted">
</p-triStateCheckbox>




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 { TriStateCheckboxModule } 
    from "primeng/tristatecheckbox";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    TriStateCheckboxModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Reference: https://primeng.org/tristatecheckbox


Article Tags :