在 AngularJS 中从父控制器上的子控制器访问文件项

Access fileitem from child controller on parent controller in AngularJS

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

子控制器:

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

我需要更新的值,即。此变量中的文件项。 任何指导将不胜感激。

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

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