无法以多次离子选择更改值 [英] Unable to change values in ion-select-multiple
问题描述
我正在使用 ion-select-multiple
.正常情况下,它工作正常.我需要预先选择一些选项.我在网上搜索并找到了解决方案,但是在预先分配了值之后,现在当我尝试更改时,它给了我错误.
I am using ion-select-multiple
. It works perfectly fine normally. I have a requirement to pre select few options in it. I searched the web and found the solution, but after pre assigning the values, now when I try to change, it gives me error.
这是我的 home.html
代码:
<ion-select multiple="true" okText="Okay" cancelText="Dismiss" [(ngModel)]="followers" [value]="{$value: followers}">
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
</ion-select>
home.ts
followers = ['brown','black'];
请注意,预先选择了 Brown
和 Black
,但是如果我尝试从列表中选择/取消选择任何内容,则会出现错误-
Please note, Brown
and Black
are pre selected, but if I try to select/de-select anything from list, it gives error -
ExpressionChangedAfterItHasBeenCheckedError:检查表达式后,表达式已更改.先前的值:型号:12w 3".当前值:模型:[object Object]".
如果我删除以下代码,此错误将消失: [value] ="{$$ value:followers}"
.
This error goes away if I remove this code: [value]="{$value: followers}"
.
如何处理此错误?
添加错误屏幕截图:
推荐答案
将这段代码添加到您的compoent.ts文件中...
Add thid piece of code to your compoent.ts file...
import { Component, Input, ChangeDetectionStrategy,ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'component',
templateUrl: 'component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
constructor(private cdRef:ChangeDetectorRef){}
ngAfterViewInit() {
this.cdRef.detectChanges();
}
这篇关于无法以多次离子选择更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!