Angular PrimeNG Form RadioButton Label Component
Last Updated :
29 Nov, 2022
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 Form RadioButton Label Component in Angular PrimeNG.
The RadioButton Component allows the user to select one option at a time from a set.
Syntax:
<p-radioButton
value="..."
label="..."
[(ngModel)]="...">
</p-radioButton>
Angular PrimeNG Form RadioButton Label Component Properties:
- value: It is used to set the value of the radio button. It is of string data type, the default value is null.
- label: It is used to set the label of the radio button. It is of string data type, the default value is null.
Creating Angular Application & module installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: It will look like the following.
To run the above file run the below command:
ng serve --save
Example 1: This basic example illustrates the use of the Angular PrimeNG Form RadioButton Label Component.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >
Angular PrimeNG Form Radiobutton Label Component
</ h5 >
< p-radioButton
value = "val1"
label = "Option 1"
[(ngModel)]="gfg">
</ p-radioButton >
< p-radioButton
value = "val2"
label = "Option 2"
[(ngModel)]="gfg">
</ p-radioButton >
< p-radioButton
value = "val3"
label = "Option 3"
[(ngModel)]="gfg">
</ p-radioButton >
< p-radioButton
value = "val4"
label = "Option 4"
[(ngModel)]="gfg">
</ p-radioButton >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent { }
|
Javascript
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 {RadioButtonModule} from 'primeng/radiobutton' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
RadioButtonModule,
FormsModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
|
Output:
Example 2: This is another example that illustrates the use of the Angular PrimeNG Form RadioButton Label Component.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >
Angular PrimeNG Form Radiobutton Label Component
</ h5 >
< p-radioButton
value = "val1"
label = "DSA Self-Paced"
[(ngModel)]="gfg">
</ p-radioButton >
< br >< br >
< p-radioButton
value = "val2"
label = "System Design"
[(ngModel)]="gfg">
</ p-radioButton >
< br >< br >
< p-radioButton
value = "val3"
label = "C++ STL"
[(ngModel)]="gfg">
</ p-radioButton >
< br >< br >
< p-radioButton
value = "val4"
label = "Full Stack Development"
[(ngModel)]="gfg">
</ p-radioButton >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent { }
|
Javascript
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 {RadioButtonModule} from 'primeng/radiobutton' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
RadioButtonModule,
FormsModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
|
Output:
Reference: https://primefaces.org/primeng/radiobutton
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...