ngx-star-rating-enhanced-enhanced

2.1.0 • Public • Published

ngx-star-rating-enhanced

Angular Star Rating (ngx star rating)

Simple Angular rating control from angular2 application using fontawesome icon.

Demo can be found here

ngx-star-rating-enhanced angular rating

Installation

  1. Install npm module:

    npm install ngx-star-rating-enhanced --save

  2. Include fontawesome css:

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

Usage

Import NgxStarRatingModule module in your app, and use a component in your html:

  import { NgxStarRatingModule } from 'ngx-star-rating-enhanced';
  
  // Include tag into your component
  <ngx-star-rating-enhanced [formControl]="rating" [id]="'rating'" [disabled]="true"></ngx-star-rating-enhanced>
  • <ngx-star-rating-enhanced>:
    • `[(ngModel)] | formControl = ngModel or formControl
    • '[id] = Unique id for each control
    • [disabled]="true|false" = Enable/Disable star rating. Default is false.

Sample

// app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NgxStarRatingModule } from 'ngx-star-rating-enhanced';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgxStarRatingModule,
    FormsModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

// app.component.ts
import { Component } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],

})
export class AppComponent {
  public form: FormGroup;

  constructor(NgxStarRatingEnhanced fb: FormBuilder){
    this.rating3 = 0;
    this.form = this.fb.group({
      rating: ['', Validators.required],
    })
  }
}

// app.component.html
<form [formGroup]="form">
    <ngx-star-rating-enhanced formControlName="rating" [id]="'rating'"></ngx-star-rating-enhanced>
    <div>Rating: {{form.value.rating}}</div>
    <p>form is valid: {{ form.valid ? 'true' : 'false' }}</p>
</form>

Package Sidebar

Install

npm i ngx-star-rating-enhanced-enhanced

Weekly Downloads

1

Version

2.1.0

License

MIT

Unpacked Size

52.2 kB

Total Files

47

Last publish

Collaborators

  • shyam_bandla