2017-01-01 79 views
2

我堅持了這個問題好幾天。
我用angular file upload來上傳圖片。 我可以將圖像上傳到服務器,我可以從服務器獲取響應圖像url。如何將數據從功能傳遞到角度控制器範圍

但我無法將響應圖像的網址到我的控制器的$scope,因此我無法保存到外部控制器的網址。

以下是我的代碼的一部分。

.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 

    }; 

}]); 

在此先感謝。

回答

1

剛分配的價值,

$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; 
}; 
相關問題