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. I have implemented binding in component. So far, I have tried this-


    $onInit() {

    this.feedFileInfo = 'abc';//here it is updated
        name: 'customFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            return this.queue.length < 10;
this.uploader.onAfterAddingFile = function(fileItem) {
        this.feedFileInfo = 'xyz';//this value is not being updated to feedFileInfo variable and hence cannot be obtained in parent controller'onAfterAddingFile', fileItem);

I need the updated value ie. fileitem in this variable.
Any guidance would be appreciated.


You use the this from the declared function, not the outer one.
One classical workaround is to use:

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

Answered By – PhiLho

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.