我的页面上有多个mat-button-toggle-group。代码如下。
<li *ngFor="let item of itemList">
<mat-button-toggle-group #group{{item.id}}="matButtonToggleGroup" [(value)]="item.id" [(name)]="item.id" multiple>
<mat-button-toggle value="add_to_wishlist"></mat-button-toggle>
<mat-button-toggle value="add_to_cart"></mat-button-toggle>
</mat-button-toggle-group>
</li>
我希望它在页面加载时出现,如果该项目在愿望清单或购物车中,则按钮切换将切换。
在组件中,我对此进行了处理:
let cartList : ....
for (let i = 0; i < cartList.length; i++) {
let itemId = cartList[i].itemId;
this[itemId] = ['add_to_cart'];
}
for (let i = 0; i < wishList.length; i++) {
let itemId = wishList[i].itemId;
if(this[itemId])
this[itemId] = this[itemId].push('add_to_wishlist');
else
this[itemId] = ['add_to_wishlist'];
}
但是我收到此错误:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'name: I100001'. Current value: 'name: undefined'.