通过readAsDataURL从文件输入角度读取文件不起作用

时间:2015-10-26 10:54:40

标签: javascript jquery angularjs

我有以下代码。

void mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(mousePressed==true){ if(!rectangle){ rectangle=new QGraphicsRectItem; this->addItem(rectangle); rectangle->setPen(QPen(Qt::red,4,Qt::SolidLine)); rectangle->setPos(origPoint); } float top = qMin(origPoint.y(), event->scenePos().y()); float left = qMin(origPoint.x(), event->scenePos().x()); rectangle->setPos(left, top); rectangle->setRect(0, 0, qAbs(event->scenePos().x() - origPoint.x()), qAbs(event->scenePos().y() - origPoint.y())); qDebug() << top << left << origPoint << event->scenePos(); } else QGraphicsScene::mouseMoveEvent(event); }

directive

.directive('area', function () { return { link: function (scope, el, attrs) { var fileReader = new FileReader(); fileReader.onload = function (e) { scope.image = e.target.result; scope.$apply(); } el.on('change', function () { fileReader.readAsDataURL(el[0].files[0]); }); } }; });

controller

当我将图像添加到文件输入时,我得到以下错误

.controller('areaController', ['$scope', function ($scope) { $scope.image = ""; } ] );

1 个答案:

答案 0 :(得分:1)

我猜您应该将其修改为

el.on('change', function (e) {
 var files = (e.srcElement || e.target).files
    fileReader.readAsDataURL(files[0]);
 });