无法将我的范围变量绑定到Angularjs中的ng-src指令中

时间:2019-03-25 09:34:31

标签: javascript angularjs

我尝试从页面的s3存储桶中获取图片网址,我在angularjs文件中获取了网址,但无法将其绑定到ng-src指令中

这是我的观点

<img ng-src="{{imgData}}" />

这是我的angularjs控制器:

app.controller('Sample', function($scope) {
  AWS.config.update({
    accessKeyId: '',
    secretAccessKey: ''
  });
  AWS.config.region = "us-east-1";
  $scope.s3Url = '';
  var bucket = new AWS.S3({
    params: {
      Bucket: 'mybucketname',
      Prefix: 'UPLOADS'
    }
  });
  bucket.listObjects(function(err, data) {
    if (err) {
      console.log(err);
    } else {
      console.log(data.Contents[1]);
      $scope.imgData = $scope.s3Url + data.Contents[1].Key;
      console.log($scope.imgData);
    }
  });
});

我在控制台中获得了确切的网址

1 个答案:

答案 0 :(得分:0)

假设您正确获取了imageData,然后尝试以下操作。

<img ng-src="'{{imgData}}'" />
相关问题