选择后的角度数组更改ExpressionChangedAfterItHasBeenCheckedError

时间:2018-09-12 14:39:12

标签: angular

我正在尝试从Web服务加载值列表, 该列表取决于下拉列表。

serviceA,serviceB,serviceC均已加载到ngOnInit();

ngOnInit() {
this.serviceA  = this.someWebService.getDataA().subscribe(  (res) => {
        this.serviceA =  res;
    });
this.serviceB  = this.someWebService.getDataB().subscribe(  (res) => {
        this.serviceB =  res;
    });
this.serviceC  = this.someWebService.getDataC().subscribe(  (res) => {
        this.serviceC =  res;
    });

}

<table [mfData]="data" #mf="mfDataTable">
<tr *ngFor="let item of mf.data>
...

但是当我选择选择下拉菜单时,我交换了数据列表

if(select === A)
this.data = this.serviceA;

if(select === B)
this.data = this.serviceB;

if(select === C)
this.data = this.serviceC;

注意:我不能只做每个人

ngFor="let item of serviceA", ngFor="let item of serviceB", ngFor="let item of serviceC"

由于自定义表格,我只想将this.data(用于表格)交换为 来自Web服务的下拉菜单。

    ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. 
Previous value: 'undefined: [object Object],[object Object],[object Object],...

我检查了更改,但没有帮助。我想问为什么会发生此错误,以及如何解决?

0 个答案:

没有答案