简体   繁体   English

悬停在角材料图标

[英]angular material icon on hover

I have made a star rating component using angular material icon: 我使用角形材质图标制作了星级评分组件:

<span>
  <mat-icon *ngFor="let star of stars | keyvalue" (click)="check(star.key)" [ngClass]="{'checked': star.value === 'star'}">{{star.value}}</mat-icon>
</span>

And the ts: ts:

export class StarComponent implements OnInit {
  @Input() star_type: String = 'star_border';
  @Input() nbStar: Number = 1;

  stars: Array<String> = [];

  constructor() { }

  ready() {
    for (let i = 0; i < this.nbStar; i++) {
      this.stars.push(this.star_type);
    }
  }
  ngOnInit() {
    console.log(this.stars);
  }

  ngOnChanges() {
    this.ready();
  }

  check(index) {
    if (this.stars[index] === 'star_border') {
      for (let i = 0; i <= index; i++) {
        this.stars[i] = 'star';
      }
    }
    else {
      for (let i = this.stars.length - 1; i > index; i--) {
        this.stars[i] = 'star_border';
      }
    }
  }

}

Now, I would like to change the star.value on hover: If the star.value is star, I want on hover the value change with star_border. 现在,我想在悬停时更改star.value:如果star.value是star,我想在悬停时使用star_border更改值。 (If the star value is star_border I just already change the color) (如果star值为star_border,我已经更改了颜色)

I have no idea how doing this. 我不知道该怎么做。 If someone can help me, thanks. 如果有人可以帮助我,谢谢。

Edit for more clearance: 编辑以获得更多许可:

I have my component rendered like this: 我的组件呈现如下:

<mat-icon>[VALUE]</mat-icon>[...]<mat-icon>[VALUE]</mat-icon>
// [VALUE] is star or star_border (change on click)

If user mouseover the mat-icon and the value of the mat-icon is star, I want to change with star_hover (only the time the user hover the mat-icon) 如果用户将鼠标悬停在mat-icon上并且mat-icon的值为star,那么我想使用star_hover进行更改(仅当用户将mat-icon悬停时)

(Sorry I'm not high friendly with english) (对不起,我对英语不太友善)

Here is the change you can make - 这是您可以进行的更改-

html HTML

<span>
  <mat-icon *ngFor="let star of stars | keyvalue" (mouseenter) ="updateStar(star)" (click)="check(star.key)" [ngClass]="{'checked': star.value === 'star'}">{{star.value}}</mat-icon>
</span>

ts TS

updateStar(star){
    if(star.value == 'star'){
        star.value = 'star_hover';
    }else{
      //star.value = 'star'; //you may light to reverse it
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM