2014-10-03 53 views
0

我必须在上传完成后才能获取模态图片。所以我打开一个模式($ scope.openResizeModal()),并把我的照片放在我的范围内。img ng-src:TypeError:将圆形结构转换为JSON

uploads.client.controller.js

$scope.openResizeModal = function (flow) { 
     $scope.pictureToCrop = {}; 
     $scope.pictureToCrop = flow.files[0]; 
} 

然后我尝试打印我的HTML视图:

调整大小,modal.client.view.html

<img-cropped src="{{pictureToCrop}}" selected='selected(cords)'></img-cropped> 

而且AngularJS告诉:

Error: [$interpolate:interr] Can't interpolate: {{pictureToCrop}} 
TypeError: Converting circular structure to JSON 

我甚至试着用经典

<img src={{pictureToCrop}} /> 

但它是一样的。

这里是我的指令:

angular.module('uploads').directive('imgCropped', function() { 
return { 
    restrict: 'E', 
    replace: true, 
    scope: { src: '@', selected: '&' }, 
    link: function (scope, element, attr) { 
     var myImg; 
     var clear = function() { 
      if (myImg) { 
       myImg.next().remove(); 
       myImg.remove(); 
       myImg = undefined; 
      } 
     }; 

     scope.$watch('src', function (nv) { 
      clear(); 
      if (nv) { 
       element.after('<img />'); 
       myImg = element.next(); 
       myImg.attr('src', nv); 
       $(myImg).Jcrop({ 
        trackDocument: true, 
        onSelect: function (x) { 
         scope.$apply(function() { 
          scope.selected({ cords: x }); 
         }); 
        }, 
        aspectRatio: 1/1.4 
       }, function() { 
        // Use the API to get the real image size 
        var bounds = this.getBounds(); 
        pwGlobal.boundx = bounds[0]; 
        pwGlobal.boundy = bounds[1]; 
       }); 
      } 
     }); 
     scope.$on('$destroy', clear); 
    } 
}; 

});

谢谢大家!

+0

为了帮助你,也许你可以提供另一半的代码(指令)? – 2014-10-03 08:55:31

+0

我将它添加到我的问题中。 – vjarysta 2014-10-03 09:42:21

回答

0

这是一个流动的内部问题:

 var fileReader = new FileReader(); 
     fileReader.readAsDataURL(flow.files[0].file); 
     fileReader.onload = function (event) { 
      $scope.pictureToCrop = event.target.result; 
     }; 

解决我的问题。图像以base64编码转换。

相关问题