在点击星星时,无法重新执行ngOnChanges.
来源:6-11 本章实战
Maybrittnels4034018
2017-08-02
stars.component.ts:
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
@Component({
selector: 'app-stars',
templateUrl: './stars.component.html',
styleUrls: ['./stars.component.css']
})
export class StarsComponent implements OnInit, OnChanges {
@Input()
rating = 0;
@Output()
ratingChage: EventEmitter<number> = new EventEmitter();
stars: boolean[];
@Input()
readonly: boolean;
constructor() { }
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges): void {
this.stars = [];
for (let i = 1; i <= 5; i++) {
this.stars.push(i > this.rating);
}
}
clickStart(index: number) {
if (this.readonly) {
this.rating = index + 1;
this.ratingChage.emit(this.rating);
}
}
}
stock-form.component:
<app-stars [(rating)]="stock.rating" [readonly]="true" ></app-stars>写回答
1回答
-
ratingChange单词写错了。
022017-08-03
相似问题