Angular PrimeNG Form Rating Disabled Component
Angular PrimeNG is an open-source library that consists 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 Angular PrimeNG Form Rating Disabled Component.
The Form Rating Component is a selection input based on the star icon. It can be usually seen on product pages of e-commerce websites like Amazon, Flipkart, Alibaba, etc.
Syntax:
<p-rating [ngModel]="..." disabled="true" stars="..." iconCancelClass="..."> </p-rating>
Angular PrimeNG Form Rating Disabled Component properties:
- stars: It indicates the number of stars to be shown. It is of number datatype, the default value is 5.
- disabled: When it is set to true, the rating should be disabled. It is of the boolean data type, the default value is false.
- iconCancelClass: It is used to set the class of the ‘cancel’ icon. It is of string data type, the default value is pi pi-ban.
Creating Angular Application and Installing the Module:
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: Finally, Install PrimeNG in your given directory.
npm install primeng --save npm install primeicons --save
Project Structure: The project Structure will look like this after following the above steps:

To run the above file run the below command:
ng serve --save
Example 1: Below is the code example that illustrates the use of the Angular PrimeNG Form Rating Disabled Component.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Rating Disabled Component.</ h5 > < p-rating [ngModel]="gfg" disabled = "true" stars = "3" > </ p-rating > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { gfg: number; } |
- app.module.ts:
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 {RatingModule} from 'primeng/rating' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, RatingModule, FormsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Example 2: Below is another code example that illustrates the use of the Angular PrimeNG Form Rating Disabled Component using the cross icon.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Form Rating Disabled</ h5 > < p-rating [ngModel]="gfg" disabled = "true" stars = "5" iconCancelClass = "pi pi-times" > </ p-rating > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { gfg: number = 3; } |
- app.module.ts:
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 {RatingModule} from 'primeng/rating' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, RatingModule, FormsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Reference: https://primefaces.org/primeng/rating
Please Login to comment...