Angular ngx Bootstrap Rating Component
Last Updated :
07 Mar, 2024
Angular ngx bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites.
In this article, we will know how to use Rating in angular ngx bootstrap. Rating is used to make a component that will be shown by using stars.
Installation syntax:
npm install ngx-bootstrap --save
Approach:
- First, install the angular ngx bootstrap using the above-mentioned command.
- Add the following script in index.html
<link href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css” rel=”stylesheet”>
- Import rating component in module.ts
- In app.component.html make a rating component.
- Serve the app using ng serve.
Example:
index.html
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" />
< base href = "/" />
< meta name = "viewport" content =
"width=device-width, initial-scale=1" />
< link href =
rel = "stylesheet" />
< link rel = "icon" type = "image/x-icon" href = "favicon.ico" />
< link href =
rel = "stylesheet" />
rel = "stylesheet" />
</ head >
< body class = "mat-typography" >
< app-root ></ app-root >
</ body >
</ html >
|
app.component.html
< div id = "gfg" >
< rating [(ngModel)]="rate" [max]="max"
[readonly]="isReadonly">
</ rating >
</ div >
< div class = "card" >
< pre class = "card-block card-header"
style = "margin: 15px 0;" >
GeeksforGeeks: < b >{{rate}}</ b >
</ pre >
</ div >
|
app.module.ts
import { NgModule } from '@angular/core' ;
import { FormsModule, ReactiveFormsModule }
from '@angular/forms' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { RatingModule }
from 'ngx-bootstrap/rating' ;
import { AppComponent }
from './app.component' ;
@NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
ReactiveFormsModule,
RatingModule.forRoot()
]
})
export class AppModule { }
|
app.component.css
.card{
margin : 30px ;
}
#gfg{
margin : 30px ;
}
|
app.component.ts
import { Component, OnInit,LOCALE_ID }
from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
max = 10;
rate = 10;
isReadonly = true ;
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...