hughjdavey / ngx-stars

Simple stars rating component for Angular >= 2
Creative Commons Zero v1.0 Universal
18 stars 9 forks source link

Reinitialise issue #3

Closed Navin-vis closed 4 years ago

Navin-vis commented 4 years ago

Can't able to blank the star fill after submitting the value first time...

hughjdavey commented 4 years ago

Hi @Navin-vis which version are you using? Do you mean to blank the star component with your mouse/touch, or with code? I am able to submit a value then blank the stars, you just have to hover over them to the left until 0 are filled in, then click and they should stay blank

Navin-vis commented 4 years ago

Hi @hughjdavey I am using current version , I mean to say when i set the value it worked well but after submitting that value i want to blank the star value by code that mean when i set the value for the first time in the variable after submitting the value i use to blank the variable but it not set the star value blank

hughjdavey commented 4 years ago

Ok I think I understand. You can use the setRating method of NgxStarsComponent to do this. Below is a small demo of some stars set to 4 stars when the page loads, and some buttons which use setRating to change the rating via code at runtime. Does this help?

@Component({
  template: `
      <div style="padding: 5rem; display: flex; flex-direction: column; align-items: center;">
        <ngx-stars [size]="4" [initialStars]="4"></ngx-stars>
        <button style="margin-top: 1rem;" (click)="onSetStars(0)">Set to 0</button>
        <button style="margin-top: 1rem;" (click)="onSetStars(1)">Set to 1</button>
        <button style="margin-top: 1rem;" (click)="onSetStars(2)">Set to 2</button>
        <button style="margin-top: 1rem;" (click)="onSetStars(3)">Set to 3</button>
        <button style="margin-top: 1rem;" (click)="onSetStars(4)">Set to 4</button>
        <button style="margin-top: 1rem;" (click)="onSetStars(5)">Set to 5</button>
      </div>
  `,
  styles: []
})
export class ScratchComponent {

  // @ts-ignore
  @ViewChild(NgxStarsComponent)
  starsComponent: NgxStarsComponent;

  onSetStars(stars: number): void {
    this.starsComponent.setRating(stars);
  }
}
hughjdavey commented 4 years ago

@Navin-vis did this solve your issue?

Navin-vis commented 4 years ago

Hi @hughjdavey Yes mate it worked.... Thank you