[英]Access fileitem from child controller on parent controller in AngularJS
I am using angular file uploader in child component and need to access the fileitem when onAfterAddingFile is fired. 我在子组件中使用角度文件上传器,并且在触发onAfterAddingFile时需要访问fileitem。 I have implemented binding in component. 我已经在组件中实现了绑定。 So far, I have tried this- 到目前为止,我已经尝试过
Childcontroller: 子控制器:
$onInit() {
this.feedFileInfo = 'abc';//here it is updated
this.uploader.filters.push({
name: 'customFilter',
fn: function(item /*{File|FileLikeObject}*/, options) {
return this.queue.length < 10;
}
});
this.uploader.onAfterAddingFile = function(fileItem) {
console.log('fileItem');
this.feedFileInfo = 'xyz';//this value is not being updated to feedFileInfo variable and hence cannot be obtained in parent controller
console.info('onAfterAddingFile', fileItem);
};
I need the updated value ie. 我需要更新的值,即。 fileitem in this variable. 这个变量中的fileitem。 Any guidance would be appreciated. 任何指导将不胜感激。
You use the this
from the declared function
, not the outer one. 您可以从声明的function
使用this
,而不是外部function
。
One classical workaround is to use: 一种经典的解决方法是使用:
var that = this;
this.uploader.onAfterAddingFile = function (fileItem) {
that.feedFileInfo = 'xyz';
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.