我迭代数组包含对象:模板不更新后模型改变
<tr *ngFor="let file of files | orderBy: 'id':ascending:true | paginate: {id: 'FilePagination',itemsPerPage: 20, currentPage: p}">
<th [innerHTML]="project.files.indexOf(file)+1" scope="row"></th>
<td><a href="{{file.uri + token}}" target="_blank"><i class="fa"
[class.fa-file-audio-o]="types.audio.includes(file.type)"
[class.fa-file-pdf-o]="types.document.includes(file.type)"></i>{{"
" + file.fullName}}</a>
</td>
<td>{{file.size}}</td>
<td>{{file.timestamp | timeCalc}}</td>
<td *ngIf="adminMode">
<button type="button" (click)="deleteFile(file)"
class="fa fa-trash-o btn btn-link p-0" title="Löschen"></button>
</td>
</tr>
调用DELETEFILE方法:
deleteFile(file: File) {
this.loading = true;
this.fileService.deleteFile(file).subscribe(
message => this.information = message,
error => {
this.loading = false;
this.errorMessage = error;
},
() => {
this.files.splice(this.files.indexOf(file), 1);
this.loading = false;
}
)
}
的订阅呼叫完成后,被删除的文件不会被删除从视图。尽管如此,它肯定会从数组中移除,因为数组中所有文件的索引都会改变。这里有两张截图显示了怪异的行为:
删除之前:
删除后:
该代码工作在f或我,所以这是相当头疼的人。 视图中对象的实例与正在被删除的实例完全相同,对吗? http://plnkr.co/edit/lSf7NX85HSDv4frgnXCc?p=preview – silentsod