Socket
Socket
Sign inDemoInstall

ng-rating-bar

Package Overview
Dependencies
5
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ng-rating-bar

[Stackblitz Demo](https://stackblitz.com/edit/ng-rating-bar "Demo")


Version published
Maintainers
1
Install size
11.2 kB
Created

Readme

Source

Rating

Stackblitz Demo

Import

import { NgRatingBarModule } from 'ng-rating-bar';

@NgModule({
  declarations: [...],
  imports: [
    BrowserModule,
	  NgRatingBarModule
  ]
})

Simple usage

<ng-rating-bar 
  [(value)]="value" 
  [ratingCount]="10" 
></ng-rating-bar>
Value is {{ value }}

Properties

NameTypeRequiredDefault
valuenumberRequired0
ratingCountnumberRequired5
disabledbooleanOptionalfalse
resetAblebooleanOptionalfalse
colorActivestringOptional#edb867
colorDefaultstringOptional#d2d2d2
stylesObjectOptional{ fontSize: '28px', backgroundColor: '', margin: '5px' }

Events

EventParameterDescription
valueChange(value: number)Callback to invoke when value was changed
hoverChange(value: number)Triggered when on hover change

Usage with output event

    <ng-rating-bar
      [value]="value"
      (valueChange)="onValueChange($event)"
      [ratingCount]="10"
    ></ng-rating-bar>

In component

onValueChange($event: number) {
  this.value = $event
}

Disabled rating

  <ng-rating-bar
    [value]="5"
    [ratingCount]="7"
    [disabled]="true"
  ></ng-rating-bar>

Using in reactive form

In html view

<form [formGroup]="myForm">
      <ng-rating-bar
        [control]="myForm.get('rating')"
        [ratingCount]="ratingCount"
      ></ng-rating-bar>
      
      <p *ngIf="myForm.get('rating').touched && myForm.get('rating').hasError('required')">
        Field is required
      </p>

  <p>
    <button (click)="submitForm()">Submit</button>
  </p>
  </form>

In Component

  ngOnInit() {
    this.myForm = this.fb.group({
      rating: [null, Validators.required]
    });
  }

  submitForm() {
    this.myForm.get('rating').markAllAsTouched();
    console.log(this.myForm.value);
  }

Hover output

  Value is:
  <b
    [class.excellent]="hoverValue === 7"
    [class.good]="hoverValue > 4 && hoverValue < 7"
    [class.notBad]="hoverValue > 2 && hoverValue <= 4 "
    [class.bad]="hoverValue <= 2"
  >
    {{ hoverValue }}
  </b>
  <p>

    <ng-rating-bar
      [(value)]="value2"
      (hoverChange)="hoverValue = $event"
      [ratingCount]="7"
    ></ng-rating-bar>
  </p>

Set custom color

  <ng-rating-bar
    [(value)]="value" 
    [ratingCount]="ratingCount" 
    colorActive="red" 
    colorDefault="gray"
  ></ng-rating-bar>

Custom styles

  <ng-rating-bar
      value="5"
      [ratingCount]="10"
      [styles]="{backgroundColor: '#0965ee', margin: '10px', fontSize: '32px'}"
    ></ng-rating-bar>

Keywords

FAQs

Last updated on 26 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc