Usage in Angular :
Using an Angular CLI there are two steps for Integration of Rating component.
1) Include the `CUSTOM_ELEMENTS_SCHEMA` in the modules that uses the components, in most cases we can add it in our app level module.
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}
2) Call `defineCustomElements(window)` from `main.ts` or other appropriate place.
import { defineCustomElements } from '@logisticinfotech/rating-component/dist/loader';
defineCustomElements(window);
=> Using `ngModel` :
<li-rating ngDefaultControl [(ngModel)]="ratingValue"></li-rating>
=> Passing value using ‘value’ attribute :
<li-rating value="1.8" (input)="onChangeRatingValue($event)"></li-rating>
=> Using `form-control` in case we need to include it in ReactiveForm Validation :
<li-rating ngDefaultControl formControlName="rating"></li-rating>
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
form : FormGroup ;
constructor(
public formBuilder: FormBuilder
) {
this.form = this.formBuilder.group({
rating: ['', [Validators.required]]
});
}
ngOnInit() {
// GETTING VALUE CHANGES EVENT IN FORM-CONTROL
this.reactiveForm.valueChanges.subscribe(val => {
console.log(this.form.value);
});
}
=> Handling Rate change event and getting rate value as below:
onChangeRatingValue(event) {
console.log('rating value =>' , event.target.value);
}
=> While using font-awesome we need to use `setSvgString` method to pass SVG as string :
import { ViewChild, ElementRef } from '@angular/core';
@ViewChild('ELEMENT_ID') liRating: ElementRef ;
this.liRating.nativeElement.componentOnReady()
.then(() => {
this.liRating.nativeElement.setSvgString('SVG_HTML');
});
Angular demo is also available to given
link .