Http.Request-跟踪状态代码似乎不起作用

时间:2019-04-05 11:07:46

标签: angular

我想将文件上传到某个位置,然后显示成功上传文件的列表。上传部分效果很好,列表部分效果不明显。

我这样发出一个上传文件请求(myFiles是myFile类的数组):

public qFile: myFile;
@ViewChild('file') fileSelector: ElementRef;
upload(files: any){

if(files.length === 0) return;

const formData = new FormData();

for (let file of files) 
  formData.append(file.name, file);

const uploadReq = new HttpRequest(
      'POST',
      'https://adddressofmyservice/uploadFiles',
      formData,
      {
        reportProgress: true
      }
    );

this.http.request(uploadReq).subscribe(
  event => {
    if (event.type === HttpEventType.UploadProgress)
      this.progress = Math.round((100 * event.loaded) / event.total!);
    else if (event.type === HttpEventType.Response) {
      this.fileSelector.nativeElement.value = '';
      if (event.status === 200) for (let file of files) {
        this.qFile.FileName = file.name;
        this.qFile.FileExtension = file.type;
        this.qFile.FileSize = file.size;
        this.myFiles.push(this.qFile);
      }
    }
  });

但是什么都没有添加到列表中。

应该基于此数组添加标签,但不显示任何内容:

<div class="row" *ngFor="let selectedItem of myFiles; let y = index">
    <div class="form-group col-xs-6">
        <div class="col-lg-12 col-md-12 col-sm-12 form-group">
            <label id="UNIQUELABEL{{ y }}">{{ selectedItem.FileName }}</label>
        </div>
    </div>
</div>

0 个答案:

没有答案