【发布时间】:2017-11-21 10:26:36
【问题描述】:
我正在使用在 ngfor 中循环的 ngclass 中的方法。 当循环发生时,方法返回值一直在变化。
但是我遇到了类似的错误
错误错误:ExpressionChangedAfterItHasBeenCheckedError:表达式 检查后有变化。以前的值:'background_pink'。 当前值:'background_blue'。
代码是这样的
组件.ts
getRandomColor() {
const changedColor = _.sample(this.colors);
return changedColor;
}
component.html
<a href="https://www.leelag.com/tag/laravel" *ngFor="let tag of bookDetails.tags">
<label [ngClass]="['label', 'well', 'well-sm', getRandomColor()]">{{ tag.name }}</label></a>
循环时一直显示上述错误。 如何解决?
【问题讨论】:
标签: angular