Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 对象参数不工作的角度变化检测_Angular_Angular Changedetection - Fatal编程技术网

Angular 对象参数不工作的角度变化检测

Angular 对象参数不工作的角度变化检测,angular,angular-changedetection,Angular,Angular Changedetection,我有以下组件代码。在mycomponent.ts中,我定义了以下内容: 票证:票证[]=[] 上载计数:{[key:string]:number}={} ngOnInit(){/*从API获取票证的代码,每个票证id的init uploadCounts为0*/} incrementUploadCount(id:string,increment:number){ const counts={…this.uploadCounts};//复制上载计数 计数[id]+=增量 this.uploadCou

我有以下组件代码。在my
component.ts
中,我定义了以下内容:

票证:票证[]=[]
上载计数:{[key:string]:number}={}
ngOnInit(){/*从API获取票证的代码,每个票证id的init uploadCounts为0*/}
incrementUploadCount(id:string,increment:number){
const counts={…this.uploadCounts};//复制上载计数
计数[id]+=增量
this.uploadCounts={…counts};//克隆计数-->新上载计数
console.log(this.uploadCounts);//这会正确地实时记录uploadCounts更改,但是
//模板中的结果仍然没有更新。
this.cdr.detectChanges();//手动检测更改
}
添加文件(票证:票证,文件){
this.incrementUploadCount(ticket.id,1);//将此票据的上载计数增加1。
这个.ticketSvc.uploadFile(ticket,file).then(res=>{
this.incrementUploadCount(ticket.id,-1);//将此票据的上载计数减少1。
});
}
在我的
component.html
中,我有:


{{ticket.name}
正在上载{{uploadCounts[ticket.id]}}文件。。。
当触发
addFile
时,会添加文件,但是不会显示该票据的上载计数div,也不会在所有操作完成后更新(当它闪烁几毫秒并消失时)。我一直小心地确保上传状态的每次更改都会覆盖整个
uploadCounts
对象,以便检测到更改(请参阅
incrementUploadCount
方法)。我发现的所有其他问题都表明了这一点,但在这里似乎没有任何影响。你有没有想过为什么会发生这种情况,或者有没有更好的办法


注意:页面上显示了多个票据,每个票据可能有多个上传,因此需要对正在上传的票据进行某种索引)。

您能在Stackblitz上重新创建它吗?我可以试试。它是一个非常大的应用程序的一部分,所以我需要通过它,拿出一些服务。如果我能在Stackblitz上找到工作,我会更新帖子的。