BioPhoton / angular-star-rating

Star Rating Angular Component written in typescript, based on css only techniques.
MIT License
217 stars 86 forks source link

Cannot read property 'toString' of null #105

Closed fsitios closed 2 years ago

fsitios commented 5 years ago

I'm submitting a...


[x] Bug report  
[ ] Feature request

Current behavior

When using reactive forms in Angular 7 as this:

star-rating-control [starType]="'svg'" formControlName="rating" [step]="1" [rating]="0" [numOfStars]="5"></star-rating-control>

this.form = this.fb.group({
      title: [null, {
        validators: [Validators.required, Validators.minLength(3)]
      }],
      rating: [0, { validators: [Validators.required] }]
    });

and I trigger this line of code after updating the Object:

this.form.reset();

the error occurred:

_ERROR TypeError: Cannot read property 'toString' of null at StarRatingControlComponent.push../node_modules/angular-star-rating/esm5/angular-star-rating.js.StarRating.setRating (angular-star-rating.js:271) at StarRatingControlComponent.push../node_modules/angular-star-rating/esm5/angular-star-rating.js.StarRatingControlComponent.setRating (angular-star-rating.js:774) at StarRatingControlComponent.set [as rating] (angular-star-rating.js:73) at StarRatingControlComponent.push../node_modules/angular-star-rating/esm5/angular-star-rating.js.StarRatingControlComponent.writeValue (angular-star-rating.js:762) at forms.js:2066 at forms.js:3149 at Array.forEach () at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.FormControl.setValue (forms.js:3149) at FormControl.push../nodemodules/@angular/forms/fesm5/forms.js.FormControl.reset (forms.js:3190) at forms.js:3572

Expected behavior

On line 271 of "angular-star-rating.js" the this._rating value should not be null to avoid the error.

this.ratingAsInteger = parseInt(this._rating.toString(), 10);

Minimal reproduction of the problem with instructions

As I mentioned before the error occurs when the form reset() is performed.

Environment


Library version: 4.0.0-beta.3
Angular version: 7.1.0


Browser:

- [x] Chrome (desktop) version 71.0.3578.98 (Build oficial) (64 bits)
billyjov commented 2 years ago

Will come with version 6.0.0