を変更した後、私は、オブジェクトを含む配列を反復更新していない:テンプレートは、モデルが
<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