1

So i have a value in my scope called $scope.selectedComponent

Then i have the following uploader:

    var uploader = $scope.uploader = new FileUploader({
    url: 'user_resources/upload.php',
    formData: [{module_id: $state.params.id, component: $scope.selectedComponent}]
});

// FILTERS

uploader.filters.push({
    name: 'customFilter',
    fn: function(item /*{File|FileLikeObject}*/, options) {
        return this.queue.length < 10;
    }
});

// CALLBACKS

uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) {
    console.info('onWhenAddingFileFailed', item, filter, options);
};
uploader.onAfterAddingFile = function(fileItem) {
    console.info('onAfterAddingFile', fileItem);
};
uploader.onAfterAddingAll = function(addedFileItems) {
    console.info('onAfterAddingAll', addedFileItems);
};
uploader.onBeforeUploadItem = function(item) {
    console.info('onBeforeUploadItem', item);
};
uploader.onProgressItem = function(fileItem, progress) {
    console.info('onProgressItem', fileItem, progress);
};
uploader.onProgressAll = function(progress) {
    console.info('onProgressAll', progress);
};
uploader.onSuccessItem = function(fileItem, response, status, headers) {
    console.info('onSuccessItem', fileItem, response, status, headers);
};
uploader.onErrorItem = function(fileItem, response, status, headers) {
    console.info('onErrorItem', fileItem, response, status, headers);
};
uploader.onCancelItem = function(fileItem, response, status, headers) {
    console.info('onCancelItem', fileItem, response, status, headers);
};
uploader.onCompleteItem = function(fileItem, response, status, headers) {
    console.info('onCompleteItem', fileItem, response, status, headers);
};
uploader.onCompleteAll = function() {
    console.info('onCompleteAll');
};

The callback function: onCompleteItem is where i want to update the selectedComponent object however within the scope of that function i am unable to get the variables of scope

My question is how will i be able to update my variable after the file has uploaded?

2 Answers 2

2

make sure that the $scope is loaded in your controller:

.controller('AppController', ['$scope', 'FileUploader', function($scope, FileUploader) {

and after that you can update the value of the $scope.selectedComponent from anywhere in this controller.

$scope.selectedComponent = "not uploaded";

    uploader.onCompleteItem = function (fileItem, response, status, headers) {
                  $scope.selectedComponent = "upload complete";
};
Sign up to request clarification or add additional context in comments.

2 Comments

Could you please edit your answer to give an explanation of why this code answers the question? Code-only answers are discouraged, because they don't teach the solution.
@MarcRasmussen try putting a console.log($scope.selectedComponent) in the onCompleteItem function, and check if the value has been updated. and also post the errors if there's any in the logs?
1

You can get your scope this way

var scope = angular.element(document.getElementById('MyCtrl')).scope();

Haven't test it, but it should work.

1 Comment

what message are you getting?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.