ngchanges不会为可观察订阅中的数字属性值触发

时间:2018-03-05 07:09:24

标签: javascript angular

我面临问题ngChanges没有检测到一个属性更改而不是另一个属性更改,如注释中所突出显示的那样。在ngchanges中检测到对象更改,但ngchanges未检测到属性值更改。

为什么会发生这种情况以及如何解决

父组件ts

this.route.data
    .subscribe(cdata => {
        cdata.data[0].subscribe(sRow => {
            this.success = sRow;
        });
        cdata.data[1].subscribe(allRows => {
            const fullCount = Number(allRows.filter(Row => Row.ErrorCode === 0).length);
            this.successCount = fullCount;
        });       
    });
}

<gss-gridview [ListSource]="success" [PageSize]="5" (TotalItemCount)="successCount"
        (prevBtn)="prevPage($event)" (nextBtn)="nextPage($event)" 
        (approveBtn)="approve($event)" (rejectBtn)="reject($event)" (sort)="sortList($event)" 
        (filterInput)="filterList($event)"  >
        </gss-gridview>

儿童组件ts

ngOnChanges(changes: SimpleChanges) {
    const updated: SimpleChange = changes.ListSource;
    const updatedItemCount: SimpleChange = changes.TotalItemCount; // this comes as undefined
    if (updated) {
        this.success = updated.currentValue; // this is working
    }
    if (updatedItemCount) {
        this.successCount = updatedItemCount.currentValue;// not working as results are undefined
    }
}
@Input() ListSource: Array<Metric>;  
@Input() PageSize: number;  
@Input() BatchSize: number;  
@Input() TotalItemCount: number;

0 个答案:

没有答案