处理预览图片代码但由于某些问题无法对其进行排序
视图:
<img ng-src="{[vm.photo]}"/>
<input type="file" on-add-image="uploadFile"/>
指令:
.directive('onAddImage', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var onImgChange = scope.$eval(attrs.onAddImage);
element.bind('change', onImgChange);
}
};
});
控制器:
var vm = this;
$scope.uploadFile = function() {
dietImage = event.target.files[0];
var reader = new FileReader();
reader.onload = function(event) {
vm.photo = event.target.result
$scope.$apply()
}
reader.readAsDataURL(event.target.files[0]);
};
错误消息:“未捕获的TypeError:无法在FileReader.reader.onload中设置未定义的属性'photo'”