繁体   English   中英

从AngularJS的父控制器上的子控制器访问Fileitem

[英]Access fileitem from child controller on parent controller in AngularJS

我在子组件中使用角度文件上传器,并且在触发onAfterAddingFile时需要访问fileitem。 我已经在组件中实现了绑定。 到目前为止,我已经尝试过

子控制器:

    $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);
    };

我需要更新的值,即。 这个变量中的fileitem。 任何指导将不胜感激。

您可以从声明的function使用this ,而不是外部function
一种经典的解决方法是使用:

var that = this;
this.uploader.onAfterAddingFile = function (fileItem) {
  that.feedFileInfo = 'xyz';
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM