Angular PrimeNG Form Rating No Cancel 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 Form Rating No Cancel component in Angular PrimeNG. Let’s learn about the properties, along with their syntaxes that will be used in the code.
The Rating component is used to represent the rating given by the user.
Syntax:
<p-rating [cancel]="false" readonly="..."> </p-rating>
Angular PrimeNG Form Rating No Cancel Component Properties:
- readonly: We cannot change the value of the component. It is of the boolean data type, the default value is false.
- cancel: It shows a cancel icon that resets all the star’s values. It is of the boolean data type, and the default value is true.
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 is the basic example that shows how to use the Angular PrimeNG Form Rating No Cancel component.
- app.component.html:
HTML
< h1 style = "color: green" >w3wiki</ h1 > < h5 >Angualar PrimeNG Form Rating No Cancel Component</ h5 > < p-rating [cancel]="false"></ p-rating > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { } |
- 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: This is another basic example that shows how to use the Angular PrimeNG Form Rating No Cancel component using readOnly=”true”.
- app.component.html:
HTML
< h1 style = "color: green" >w3wiki</ h1 > < h5 >Angualar PrimeNG Form Rating No Cancel Component</ h5 > < p-rating [cancel]="false" readonly = "true" ></ p-rating > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { } |
- 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