【问题标题】:How to pass data from function to angular controller scope如何将数据从函数传递到角度控制器范围
【发布时间】:2017-01-01 05:24:44
【问题描述】:

我被这个问题困扰了好几天。
我使用angular file upload 上传图片。 我可以上传图片到服务器,我可以从服务器获取响应图片的url。

但我无法将响应图像 url 获取到我的控制器的 $scope,因此我无法将 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

    };

}]);

提前致谢。

【问题讨论】:

    标签: angularjs angularjs-scope angular-file-upload


    【解决方案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; 
    };
    

    【讨论】:

      猜你喜欢
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 2021-09-28
      • 1970-01-01
      • 2016-06-08
      相关资源
      最近更新 更多