Contents
- Label position
- Label template
Having trouble getting help?
Contact Support
Contact Support
Labels in Angular Rating Component
27 Apr 20246 minutes to read
You can use the showLabel
property to display a label that shows the current value of the rating. When the showLabel
property is set to true
, a label will be displayed.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<input ejs-rating id="rating" showLabel='true' value="3" />
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Label position
The rating component allows you to place the label on the top, bottom, left, or right side of the rating using the labelPosition
property.
The following label positions are supported:
- Top: The label is placed on the top of the rating.
- Bottom: The label is placed on the bottom of the rating.
- Left: The label is placed on the left side of the rating.
- Right: The label is placed on the right side of the rating.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<Label>Left Label Position</Label><br/>
<input ejs-rating id="rating1" value="3" showLabel="true" labelPosition="Left" /><br/>
<Label>Right Label Position</Label><br />
<input ejs-rating id="rating2" value="3" showLabel="true" /><br/>
<Label>Top Label Position </Label><br />
<input ejs-rating id="rating3" value="3" showLabel="true" labelPosition="Top" /><br/>
<Label>Bottom Label Position</Label><br />
<input ejs-rating id="rating4" value="3" showLabel="true" labelPosition="Bottom" />
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Label template
You can use the labelTemplate
tag directive to specify a custom template for the Label
of the rating. The current value of the rating will be passed as the value
property in the template context when building the content of the label. This allows you to include dynamic information about the rating in the template.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<input ejs-rating id="rating" value="3" showLabel="true" [labelTemplate]="labelTemplate" />
<ng-template #labelTemplate let-data="">
<span> out of 5</span>
</ng-template>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));