我想在订阅后更改数组中的一些值。
this.data = this.search.getProductsById(this.id).subscribe
((data: any) => {
this.list = data;
//Here for each price I want to change price value
for (let entry of this.list.deals.new) {
if (entry.country == 'UK') {
let p = entry.price * 1.10837; //here I change price
console.log(p); //displays new price
}
}
this.loading = true;
});
但在 HTML
中它显示旧价格,而不是 p
。如何更改它以便进入 html
新的?
最佳答案
我认为这是因为你没有在你的数组中设置新值p
,我认为它是这样的:
this.data = this.search.getProductsById(this.id).subscribe
((data: any) => {
this.list = data;
//Here for each price I want to change price value
for(let entry of this.list.deals.new){
if(entry.country == 'UK'){
entry.price *= 1.10837;
console.log(entry.price); //displays new price
}
}
this.loading = true;
}
关于javascript - 订阅时Angular 2更改数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54023517/