【发布时间】:2018-09-03 06:35:17
【问题描述】:
我使用 AngularJS 和剑道上传widjet。
HTML 标记:
<input name="files"
kendo-upload
type="file"
k-complete="vm.onFilesUploadComplete"/>
控制器:
class MyController{
constructor(){
this.myImportantVar = false;
}
onFilesUploadComplete{
this.myImportantVar = true; // << here 'this' points to another context, not to MyController
}
}
vm - 是 MyController 的别名。
Complete 事件触发,但在事件处理程序内部我无法访问“myImportantVar”,因为“this”指向另一个上下文,而不是 MyController,上下文(某些角度的上下文),我无法继续。
如何访问“myImportantVar”?
【问题讨论】:
-
当询问由您的代码引起的问题时,如果您提供人们可以用来重现问题的代码,您将获得更好的答案。该代码应该是…… 完整 – 提供重现问题所需的所有部分。见How to create a Minimal, Complete, and Verifiable example。
标签: angularjs file-upload kendo-ui