2017-01-01 18 views
2

この問題は何日間かでした。
私はangular file uploadを使用して画像をアップロードします。 イメージをサーバーにアップロードすることができます。サーバーから返信イメージURLを取得できます。関数から角度コントローラースコープにデータを渡す方法

しかし、私のコントローラの$scopeに応答イメージURLを取得できません。そのため、外部コントローラへのURLを保存できません。

以下は私のコードの一部です。事前に

.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; 
}; 
関連する問題