javascript - 在角度 9 中更改选项卡时停止上传文件
问题描述
我有一个编辑表格。
在这种形式中,我有两个选项卡 =>tab A
用于编辑和tab B
上传文件。
这是我的代码形式:
<div class="form-container">
<mat-tab-group dynamicHeight (selectedTabChange)="activateTab($event.index)" class="col-xs-12 col-sm-12 col-md-12 col-sm-offset-1 col-md-offset-2 p-0">
<mat-tab [label]="'NEWS.EDIT' | translate">
<div class="form-content">
<form class="form" id="postform" [formGroup]="newsEditForm" (ngSubmit)="onSubmit()" autocomplete="off">
<mat-form-field class="mat-form-field-fluid" appearance="outline">
<mat-label>{{'GENERAL.TITLE' | translate}} *</mat-label>
<input matInput formControlName="title" [placeholder]="'GENERAL.TITLE' | translate">
<mat-error *ngIf="newsEditForm.get('title').errors?.required">
{{ 'MAGAZINE_SHARE.VALIDATION.REQUIRED.TITLE' | translate }}</mat-error>
<mat-error *ngIf="newsEditForm.get('title').errors?.maxlength">
{{ 'MAGAZINE_SHARE.VALIDATION.MAX_LENGTH.TITLE' | translate }}</mat-error>
</mat-form-field>
</form>
</mat-tab>
<mat-tab [label]="'MAGAZINE_SHARE.FIELS' | translate">
<kt-list-file-news [postId]="postId" [apiControllerName]="apiControllerName" [postFileList]="editNewsModelOld.files" [urlShowFile]="urlShow" [coverUrlShowFile]="coverUrlShowFile" [service]="newsService" [IdName]="'postId'" [fileService]="fileService">
</kt-list-file-news>
</mat-tab>
</mat-tab-group>
<!-- end form -->
这是上传文件的组件tab B
:
<kt-list-file-news [postId]="postId" [apiControllerName]="apiControllerName" [postFileList]="editNewsModelOld.files" [urlShowFile]="urlShow" [coverUrlShowFile]="coverUrlShowFile" [service]="newsService" [IdName]="'postId'" [fileService]="fileService">
</kt-list-file-news>
现在我有一个问题。当我以上传表单上传文件时,我除了去上传,例如 32% 的百分比我更改选项卡,我需要在后台上传文件但是当我回到上传选项卡时,我看到文件上传是停了下来。有什么问题 ?我怎么解决这个问题 ???
this.subscriptions.push(this.service
.UplaodFile(uploadModel, this.apiControllerName)
.subscribe(
(event: HttpEvent<any>) => {
switch (event.type) {
case HttpEventType.UploadProgress:
if (event.total) {
this.queueProgress = Math.round(event.loaded / event.total * 100);
btnProgress[0].innerText = this.queueProgress + ' % ';
progressLine[0].width = this.queueProgress;
progressLine[0].setAttribute('style', 'width:' + 0 + '%');
progressLine[0].setAttribute('style', 'width:' + this.queueProgress + '%');
this.cdRef.detectChanges();
}
break;
case HttpEventType.Response:
if (event.body['success']) {
this.queueProgress = null;
this.alertService.success('', 'GENERAL.ADD_SUCCESS');
this.removeItem(index, false);
this.uploadBtndisabel = true;
this.fileUpload.type = this.fileType.Text;
this.previewActive = true;
this.queueProgress = 0;
this.uploadPalceHolder = undefined;
this.uploadActive = true;
this.postFileList.push(event.body['result']);
this.cdRef.detectChanges();
}
this.loading = false;
this.queueProgress = null;
break;
}
},
() => {
this.loading = false;
this.queueProgress = null;
}
));
解决方案
推荐阅读
- javascript - 我需要这些脚本才能使脚本有效并且其他计算
- java - 检查散列值是否相同
- dialogflow-es - Dialogflow 帐户链接授权代码流。如何强制重新关联帐户
- python - 主题建模内存错误:如何在有大量数据时进行 gensim 主题建模
- mysql - 我无法将 mysql 服务器连接到 EC2 实例
- php - Android Studio 应用程序未与 000webhost 通信以填充数据库
- c++ - C++:为什么在使用一次后重新声明模板的通用数据类型?
- ios - 自动布局:“水平居中”似乎无法解决 UICollectionViewCell 内宽度/x 位置的不平等歧义
- swift - 在 SwiftUI 中应该如何声明 viewModel 对象?
- vb.net - 使用公共属性 VB.net 将控件绑定到 UserControl 中的 BindingSource