2

I stuck at this problem for days.
I use angular file upload to upload image. I can upload the image to the server, and I can get the response image url from the server back.

But I can't get the response image url into my controller's $scope, therefore I cannot preserve the url to the outer controller.

The following is part of my code.

.controller('AppController', ['$scope', 'FileUploader',  function ($scope, FileUploader) {
    $scope.uploader = new FileUploader({
        url: 'http://www.example.com/upload',
    });
    $scope.imgurl = {};   // I want to put the response url here. 

    $scope.answer = function (answer) {
        $mdDialog.hide(answer);
    };


    $scope.uploader.onCompleteItem = function (fileItem, response, status, headers) {
        console.info('onCompleteItem', fileItem, response, status, headers);
        console.info(response.name); // here I can get the response url

    };

}]);

Thanks in advance.

1 Answer 1

1

Just assign the value,

 $scope.uploader.onCompleteItem = function (fileItem, response, status, headers) {
        console.info('onCompleteItem', fileItem, response, status, headers);
        console.info(response.name); // here I can get the response url
         $scope.imgurl = response.name; 
};
Sign up to request clarification or add additional context in comments.

Comments

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.