gpt4 book ai didi

angular - ngOnChanges 跟踪以前的值和新值?

转载 作者:行者123 更新时间:2023-12-03 23:30:43 27 4
gpt4 key购买 nike

在我的 angular 项目中,我试图通过点击下一个/上一个按钮来浏览列表。我有一个复选框,可以将显示的小时数从几小时更改为几天。我希望能够通过员工来回走动,并使值(value)观正确。有人告诉我,这可以通过 ngOnChanges 并跟踪以前的和新的值来完成。

这就是我所拥有的,它正在更改新值,但是我将如何更改以前的值?

 ngOnChanges(changes: { [propName: string]: SimpleChange }) {
for (let propName in changes) {
if (propName == "selectedEmployee") {
if (this.timeVar == "days") {
this.empInfo[this.selectedEmployee].STDLTD = this.empInfo[this.selectedEmployee].STDLTD * 8;
this.empInfo[this.selectedEmployee].Uncharged = this.empInfo[this.selectedEmployee].Uncharged * 8;

this.empInfo[this.selectedEmployee].PTOBase = this.empInfo[this.selectedEmployee].PTOBase * 8;
this.empInfo[this.selectedEmployee].PTOCarry = this.empInfo[this.selectedEmployee].PTOCarry * 8;
this.empInfo[this.selectedEmployee].PTOBorrowed = this.empInfo[this.selectedEmployee].PTOBorrowed * 8;
this.empInfo[this.selectedEmployee].PTOBalance = this.empInfo[this.selectedEmployee].PTOBalance * 8;
this.empInfo[this.selectedEmployee].PTORequests = this.empInfo[this.selectedEmployee].PTORequests * 8;
this.empInfo[this.selectedEmployee].PTORemaining = this.empInfo[this.selectedEmployee].PTORemaining * 8;

this.empInfo[this.selectedEmployee].ETOEarned = this.empInfo[this.selectedEmployee].ETOEarned * 8;
this.empInfo[this.selectedEmployee].ETORequests = this.empInfo[this.selectedEmployee].ETORequests * 8;
this.empInfo[this.selectedEmployee].ETORemaining = this.empInfo[this.selectedEmployee].ETORemaining * 8;
}
}
}
}

最佳答案

来自 angular documentation :

ngOnChanges(changes: SimpleChanges) {
for (let propName in changes) {
let chng = changes[propName];
let cur = JSON.stringify(chng.currentValue);
let prev = JSON.stringify(chng.previousValue);
}
}

所以,你需要 .currentValue.previousValue属性来访问当前和以前的值。

关于angular - ngOnChanges 跟踪以前的值和新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44811723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com