Fineuploader - OnComplete方法无法调用函数

时间:2017-03-31 08:50:20

标签: angular

当我尝试在其中调用“customer”值时,OnComplete()函数中的fineuploader存在问题。我正在使用Angular和TypeScript作为前端。

“客户”值未定义,因为在onComplete()块中找不到它(没有自动完成)。那么如何调用我的importCustomers函数呢?任何的想法?

提前感谢您的帮助。

enter image description here enter image description here

2 个答案:

答案 0 :(得分:2)

this范围

存在问题
ngAfterViewInit(){

var self = this; //<-- assign this before setting the new Uploader class

this.uploader = new Uploader({

....

   self.customer.importCustomers(name); //<-- use the assigned self here

}

答案 1 :(得分:0)

使用箭头功能,因为have no binding of this

onComplete = (id, name, responseJSON) => {
  if(responseJSON.success) {
    console.log("Upload done")
    this.customer.importCustomers(name)
  }
}

或者,您可以在函数参数上传递this

onComplete(id, name, responseJSON, this) {
  let _this = this;
  if(responseJSON.success) {
    console.log("Upload done")
    _this.customer.importCustomers(name)
  }
}
相关问题