星级评价显示正常,点击也正常,就是点击有时候控制台会报错是怎么回事

来源:6-11 本章实战

慕码人4796798

2017-12-20

clickStar(index: number,event){
 if(this.activatedRoute.snapshot.params['id']== undefined){
   return false;
 }else {
   this.rating = index+1;
   this.stars = [];
   for(let i = 1; i<=5; i++){
     this.stars.push(i > this.rating);
   }
   console.log(event.target);
   // this.updatedRating.emit(this.rating);
 }
}

constructor(private activatedRoute: ActivatedRoute) { }

ngOnInit() {
 this.stars = [];
 for(let i = 1; i<=5; i++){
   this.stars.push(i > this.rating);
 }
}

上面是TS里面的,这是html的

<span *ngFor="let star of stars;let i = index;" class="glyphicon glyphicon-star"
[class.glyphicon-star-empty]="star" (click)="clickStar(i,$event)"></span>

点击第五颗星星的时候就会报错

content.js:140 Uncaught TypeError: Cannot read property 'nodeName' of null

    at HTMLDocument.onMouseClick


写回答

1回答

JoJo

2017-12-23

点最后一个星报错应该是数组下标问题,检查下吧。

0
0

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程