import { Component } from '@angular/core';
import { WrRating } from 'ngwr/rating';
@Component({ imports: [WrRating] })
export class MyComponent {}Rating
Rate something with stars, in whole or half steps.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Basic
Bind a number | null with [(value)] or any Angular form.
<wr-rating [(value)]="score" />Half stars
step="0.5" allows half stars.
<wr-rating [(value)]="score" step="0.5" />Custom count
count sets the number of stars.
<wr-rating [(value)]="score" [count]="10" />Read-only
Shows a rating that cannot be changed.
<wr-rating [value]="4.5" step="0.5" [readonly]="true" />Keyboard
Arrows move one step, Home / End jump to 0 and the maximum, Delete / Backspace clears.
Gotchas
- A value above
countis drawn as full stars but stays in the model. Flag it with amax()rule.
API
| Name | Description | Type | Default |
|---|---|---|---|
count | Total number of slots. | number | 5 |
step | Step granularity — 1 for whole stars, 0.5 for halves. | 0.5 | 1 | 1 |
readonly | Read-only — value is displayed but not interactive. | boolean | false |
disabled | Disable interaction. Bound automatically from the field's disabled state when used with [formField]. | boolean | false |
size | Control size — scales the icons + gaps. | WrRatingSize | 'md' |
ariaLabel | Accessible label. Falls back to rating.label, then 'Rating'. | string | null | null |
value | The rating. Bound by [formField], or two-way via [(value)]. | number | null | null |
(touch) | Emitted on blur so a bound field can mark itself touched. | void | — |
CSS variables
Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/rating's own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-rating-empty | var(--wr-border-base) | .wr-rating |
--wr-rating-filled | var(--wr-color-warning, #ffba00) | .wr-rating |
--wr-rating-font-family | var(--wr-font-family-base) | .wr-rating |
--wr-rating-gap | 0.125rem | .wr-rating +2 variant overrides |
--wr-rating-row-radius | var(--wr-border-radius-sm) | .wr-rating__row |
--wr-rating-size | 1.25rem | .wr-rating +2 variant overrides |
Dependencies
| Built on | Form |
|---|