Bootstrap

API rating

createRating

function

createRating(props?): RatingWidget

Create a RatingWidget with given config props

Parameters

props?: PropsConfig<RatingProps>

Returns

RatingWidget

a RatingWidget


getRatingDefaultConfig

function

getRatingDefaultConfig(): RatingProps

Retrieve a shallow copy of the default Rating config

Returns

RatingProps

the default Rating config


RatingActions

interface
Methods
click

click(index): void

Method to be used when a star is clicked.

To be used in the onclick event of a star

Parameters

index: number

Star index, starting from 1

Returns

void


handleKey

handleKey(event): void

Method to be used to handle the keyboard.

To be used in the onkeydown of the rating container

Parameters

event: KeyboardEvent

Returns

void


hover

hover(index): void

Method to be used when the mouse enter in a star.

To be used in the onmouseenter of a star

Parameters

index: number

Star index, starting from 1

Returns

void


leave

leave(): void

Method to be used when the mouse leave the widget.

To be used in the onmouseleave of the rating container

Returns

void


RatingComponent

class
Implements
Constructors
new RatingComponent

new RatingComponent(): RatingComponent

Returns

RatingComponent

Properties
_widget

readonly _widget: AngularWidget<RatingWidget>


ariaLabel

ariaLabel: undefined | string

The aria label

Default Value

'Rating'


ariaLabelledBy

ariaLabelledBy: undefined | string

The aria labelled by

Default Value

''


ariaValueTextFn

ariaValueTextFn: undefined | (rating, maxRating) => string

Return the value for the 'aria-valuetext' attribute.

Param

Current rating value.

Param

maxRating value.

Default Value
(rating: number, maxRating: number) => `${rating} out of ${maxRating}`

className

className: undefined | string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: undefined | boolean

If true, the rating is disabled.

Default Value

false


hover

hover: EventEmitter<number>

An event emitted when the user is hovering over a given rating.

Event payload is equal to the rating being hovered over.

Default Value
() => {}

leave

leave: EventEmitter<number>

An event emitted when the user stops hovering over a given rating.

Event payload is equal to the rating of the last item being hovered over.

Default Value
() => {}

maxRating

maxRating: undefined | number

The maximum rating that can be given.

Default Value

10


rating

rating: undefined | number

The current rating. Could be a decimal value like 3.75.

Default Value

0


ratingChange

ratingChange: EventEmitter<number>

An event emitted when the rating is changed.

Event payload is equal to the newly selected rating.

Default Value
() => {}

readonly

readonly: undefined | boolean

If true, the rating can't be changed.

Default Value

false


resettable

resettable: undefined | boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true


slotStarFromContent

slotStarFromContent: undefined | RatingStarDirective


star

star: SlotContent<StarContext>

The template to override the way each star is displayed.

Default Value
({fill}: StarContext) => String.fromCharCode(fill === 100 ? 9733 : 9734)

tabindex

tabindex: undefined | number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0

Accessors
api

get api(): W["api"]

Returns

W["api"]


state

get state(): Signal<WidgetState<W>>

Returns

Signal<WidgetState<W>>


widget

get widget(): ContextWidget<W>

Returns

ContextWidget<W>

Methods
ngAfterContentChecked

ngAfterContentChecked(): void

A callback method that is invoked immediately after the default change detector has completed checking all of the directive's content.

Returns

void

Implementation of

AfterContentChecked.ngAfterContentChecked


ngOnChanges

ngOnChanges(changes): void

Parameters

changes: SimpleChanges

Returns

void

Inherit Doc

ngOnInit

ngOnInit(): void

Returns

void

Inherit Doc

onChange

onChange(_): void

Parameters

_: any

Returns

void


onTouched

onTouched(): void

Returns

void


registerOnChange

registerOnChange(fn): void

Parameters

fn

The callback function to register

Returns

void

Description

Registers a callback function that is called when the control's value changes in the UI.

This method is called by the forms API on initialization to update the form model when values propagate from the view to the model.

When implementing the registerOnChange method in your own value accessor, save the given function so your class calls it at the appropriate time.

Usage Notes
Store the change function

The following example stores the provided function as an internal method.

registerOnChange(fn: (_: any) => void): void {
  this._onChange = fn;
}

When the value changes in the UI, call the registered function to allow the forms API to update itself:

host: {
   '(change)': '_onChange($event.target.value)'
}
Implementation of

ControlValueAccessor.registerOnChange


registerOnTouched

registerOnTouched(fn): void

Parameters

fn

The callback function to register

Returns

void

Description

Registers a callback function that is called by the forms API on initialization to update the form model on blur.

When implementing registerOnTouched in your own value accessor, save the given function so your class calls it when the control should be considered blurred or "touched".

Usage Notes
Store the callback function

The following example stores the provided function as an internal method.

registerOnTouched(fn: any): void {
  this._onTouched = fn;
}

On blur (or equivalent), your class should call the registered function to allow the forms API to update itself:

host: {
   '(blur)': '_onTouched()'
}
Implementation of

ControlValueAccessor.registerOnTouched


setDisabledState

setDisabledState(disabled): void

Parameters

disabled: boolean

Returns

void

Description

Function that is called by the forms API when the control status changes to or from 'DISABLED'. Depending on the status, it enables or disables the appropriate DOM element.

Usage Notes

The following is an example of writing the disabled property to a native DOM element:

setDisabledState(isDisabled: boolean): void {
  this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
}
Implementation of

ControlValueAccessor.setDisabledState


trackByIndex

trackByIndex(index): number

Parameters

index: number

Returns

number


writeValue

writeValue(value): void

Parameters

value: any

Returns

void

Description

Writes a new value to the element.

This method is called by the forms API to write to the view when programmatic changes from model to view are requested.

Usage Notes
Write a value to the element

The following example writes a value to the native DOM element.

writeValue(value: any): void {
  this._renderer.setProperty(this._elementRef.nativeElement, 'value', value);
}
Implementation of

ControlValueAccessor.writeValue


RatingDirectives

interface
Properties
containerDirective

containerDirective: Directive

A directive to be applied to the main container This will handle the keydown, mouseleave, tabindex and aria attributes


starDirective

starDirective: Directive<object>

A directive to be applied on each star element

Type declaration
index

index: number


RatingProps

interface
Properties
ariaLabel

ariaLabel: string

The aria label

Default Value

'Rating'


ariaLabelledBy

ariaLabelledBy: string

The aria labelled by

Default Value

''


ariaValueTextFn

ariaValueTextFn: (rating, maxRating) => string

Return the value for the 'aria-valuetext' attribute.

Parameters

rating: number

Current rating value.

maxRating: number

maxRating value.

Returns

string

Default Value
(rating: number, maxRating: number) => `${rating} out of ${maxRating}`

className

className: string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: boolean

If true, the rating is disabled.

Default Value

false


maxRating

maxRating: number

The maximum rating that can be given.

Default Value

10


onHover

onHover: (rating) => void

An event emitted when the user is hovering over a given rating.

Event payload is equal to the rating being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}

onLeave

onLeave: (rating) => void

An event emitted when the user stops hovering over a given rating.

Event payload is equal to the rating of the last item being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}

onRatingChange

onRatingChange: (rating) => void

An event emitted when the rating is changed.

Event payload is equal to the newly selected rating.

Parameters

rating: number

Returns

void

Default Value
() => {}

rating

rating: number

The current rating. Could be a decimal value like 3.75.

Default Value

0


readonly

readonly: boolean

If true, the rating can't be changed.

Default Value

false


resettable

resettable: boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true


star

star: SlotContent<StarContext>

The template to override the way each star is displayed.

Default Value
({fill}: StarContext) => String.fromCharCode(fill === 100 ? 9733 : 9734)

tabindex

tabindex: number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0


RatingStarDirective

class
Constructors
new RatingStarDirective

new RatingStarDirective(): RatingStarDirective

Returns

RatingStarDirective

Properties
templateRef

templateRef: TemplateRef<any>

Methods
ngTemplateContextGuard

static ngTemplateContextGuard(_dir, context): context is StarContext

Parameters

_dir: RatingStarDirective

context: unknown

Returns

context is StarContext


RatingState

interface
Properties
ariaLabel

ariaLabel: string

The aria label

Default Value

'Rating'


ariaLabelledBy

ariaLabelledBy: string

The aria labelled by

Default Value

''


ariaValueText

ariaValueText: string

the aria value of the rating


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: boolean

If true, the rating is disabled.

Default Value

false


interactive

interactive: boolean

is the rating interactive i.e. listening to hover, click and keyboard events


maxRating

maxRating: number

The maximum rating that can be given.

Default Value

10


rating

rating: number

The current rating. Could be a decimal value like 3.75.

Default Value

0


readonly

readonly: boolean

If true, the rating can't be changed.

Default Value

false


resettable

resettable: boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true


star

star: SlotContent<StarContext>

The template to override the way each star is displayed.

Default Value
({fill}: StarContext) => String.fromCharCode(fill === 100 ? 9733 : 9734)

stars

stars: StarContext[]

the list of stars


tabindex

tabindex: number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0


visibleRating

visibleRating: number

the visible value of the rating (it changes when hovering over the rating even though the real value did not change)


RatingWidget

type alias

RatingWidget: Widget<RatingProps, RatingState, object, RatingActions, RatingDirectives>


StarContext

interface
Properties
fill

fill: number

indicates how much the current star is filled, from 0 to 100


index

index: number

the position of the star in the rating