ng2-file-upload响应范围

时间:2018-08-20 07:06:21

标签: typescript angular6

我想从onCompleteItem中访问响应。

如何在Uploader.onitemcomplete之外访问onitemcomplete响应

我尝试在函数外部定义数组,然后将值推入函数中,但它也无法正常工作

这是我的代码...

add(data,action){
this.data.loader = true;

this.uploader.uploadAll();
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {

  this.data.dp = JSON.parse(response);
 **HERE IS THE RESPONSE**  
 };
  //console.log(this.data.dp);
 var frmData = JSON.stringify({'fname': data.fname,'mname':data.mname,'lname':data.lname, 
'contact':data.phone, 'email':data.email, 'address':data.address, 'country':data.country, 'state':data.state, 
'pin':data.pin, 'uimg':**WANT TO  ACCESS IT HERE**});
 console.log(this.data.headers);
 if(action == 'Save'){

 this.http.post("http://127.0.0.1/ci/index.php/api/account/register",frmData,this.options)
  .map(res => res.json())
  .subscribe(data => {
  this.data.loader = false;
          this.data.message = data.message;

        this.snackBar.open('Registered Successfully.', '', {
          duration: 3000,
        });
      }

    else {
      this.snackBar.open(data.message, '', {
          duration: 3000,
        });
    }

            this.data.fname = '';
    this.data.mname = '';
    this.data.lname = '';
    this.data.phone = '';
    this.data.email = '';
    this.data.address = '';
    this.data.pin = '';
    this.data.state = '';
    this.data.country = '';


      },error => {
      this.data.message = 'Error';
      });


  }

1 个答案:

答案 0 :(得分:0)

onComplete中的代码异步执行。如果希望在调用onComplete之后执行之后的代码,则需要将其移动到它自己的方法中并调用它。

它看起来像这样:

<divs>