Open In App

Angular PrimeNG Form Rating ReadOnly 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 ReadOnly 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]="..."
    stars="..."
    readonly="true"
    iconCancelClass="...">
</p-rating>

 



Angular PrimeNG Form Rating ReadOnly Component properties:

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 ReadOnly Component.




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Form ReadOnly Component</h5>
  
<p-rating 
    [ngModel]="gfg"
    stars="5" 
    readonly="true" 
    iconCancelClass="pi pi-times">
</p-rating>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
  
export class AppComponent { 
    gfg: number = 4;
}




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 ReadOnly Component without the cancel icon.




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Form ReadOnly Component</h5>
  
<p-rating 
    [ngModel]="gfg" 
    stars="8" 
    readonly="true"
    [cancel]="false">
</p-rating>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
  
export class AppComponent { 
    gfg: number = 4;
}




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


Article Tags :