Skip to content

Use it with reactive forms

Michael Hladky edited this page Apr 20, 2018 · 3 revisions

The angular-star-rating component is very easy to use in reactive forms. To do so use the componentselector star-rating-control. Then just apply the formControlName attribute to the star rating component and place it in a formGroup

  1. Create a component with a reactive form set up. Also log the actual value of the form to the view.
    //my-form.component.ts
    import {Component} from "@angular/core";
    import {FormGroup, FormControl} from "@angular/forms";
    
    @Component({
        selector: 'my-form-component',
        template: `    
            <form [formGroup]="form">
                <star-rating-control formControlName="myRatingControl"></star-rating-control>
                <pre>{{ form.value | json }}</pre>
            </form>
        `
    })
    export class MyFormComponent {
    
        form = new FormGroup({
            myRatingControl: new FormControl('')
        });
    
    }
  2. Use the created component
    <!-- app.component.html-->
    <my-form-component></my-form-component>
Clone this wiki locally